[GH-ISSUE #285] White spaces in link destination #245

Open
opened 2026-03-03 01:25:04 +03:00 by kerem · 6 comments
Owner

Originally created by @daniel-vera-g on GitHub (May 4, 2020).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/285

The commonmark spec defines for link destinations:

a nonempty sequence of characters that does not include ASCII space or control characters, and includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses that is not itself inside a balanced pair of unescaped parentheses.

https://spec.commonmark.org/0.25/#link-destination

https://spec.commonmark.org/0.25/#example-458:

The destination cannot contain spaces or line breaks, even if enclosed in pointy brackets...

Actual Behavior

├── testFolder
│   └── test 2.md
└── test.md

And in test.md:

# Test

[Test](testFolder/test 2.md)

And use the cli tool to run markdownlint-cli test.md no errors are returned.

Expected Behavior

The right format for the link would be:

# Test

[Test](testFolder/test%202.md)

And the linter should return something along the lines of:

Links should not include spaces.....

Originally created by @daniel-vera-g on GitHub (May 4, 2020). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/285 The commonmark spec defines for link destinations: > a nonempty sequence of characters that does not include ASCII space or control characters, and includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses that is not itself inside a balanced pair of unescaped parentheses. https://spec.commonmark.org/0.25/#link-destination https://spec.commonmark.org/0.25/#example-458: > The destination cannot contain spaces or line breaks, even if enclosed in pointy brackets... ## Actual Behavior ``` ├── testFolder │ └── test 2.md └── test.md ``` And in `test.md`: ```markdown # Test [Test](testFolder/test 2.md) ``` And use the cli tool to run `markdownlint-cli test.md` no errors are returned. ## Expected Behavior The right format for the link would be: ```markdown # Test [Test](testFolder/test%202.md) ``` And the linter should return something along the lines of: > Links should not include spaces.....
Author
Owner

@mondeja commented on GitHub (Aug 25, 2020):

Next line raises a false positive for rule MD034:


[foo](http://bar /)
MD034/no-bare-urls Bare URL used [Context: "http://bar"]

Online demo

EDITED: So this proposed rule must overwrite this false positive.

<!-- gh-comment-id:680100673 --> @mondeja commented on GitHub (Aug 25, 2020): Next line raises a false positive for rule `MD034`: ```markdown [foo](http://bar /) ``` ``` MD034/no-bare-urls Bare URL used [Context: "http://bar"] ``` > [Online demo](https://dlaa.me/markdownlint/#%25m%23%20Issue%20%23285%0A%0A%5Bfoo%5D(http%3A%2F%2Fbar%20%2F)%0A) EDITED: So this proposed rule must overwrite this false positive.
Author
Owner
<!-- gh-comment-id:680118983 --> @DavidAnson commented on GitHub (Aug 25, 2020): @mondeja That is not a valid link syntax, so it appears as a bare URL. You can confirm here: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22%5Bfoo%5D%28http%3A%2F%2Fbar%20%2F%29%22%2C%22defaults%22%3A%7B%22html%22%3Afalse%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22html%22%7D%7D Specifically, it violates this clause: https://spec.commonmark.org/0.29/#example-485
Author
Owner

@DavidAnson commented on GitHub (Aug 25, 2020):

[Rereads parent issue...] Okay, in the context of this issue, that's expected - I think the point is to be sure this isn't reported as a bare link AND a violation of the proposed rule?

<!-- gh-comment-id:680120689 --> @DavidAnson commented on GitHub (Aug 25, 2020): [Rereads parent issue...] Okay, in the context of this issue, that's expected - I think the point is to be sure this isn't reported as a bare link AND a violation of the proposed rule?
Author
Owner

@mondeja commented on GitHub (Aug 25, 2020):

I think the point is to be sure this isn't reported as a bare link AND a violation of the proposed rule?

Yes, I've found a link with spaces in Markdown today and wasted some time checking why was raising MD034. Perhaps previous comment helps someone.

Some more context, if you have a list of referenced links and the first has spaces, next links also raise MD034.
Online demo

<!-- gh-comment-id:680140614 --> @mondeja commented on GitHub (Aug 25, 2020): > I think the point is to be sure this isn't reported as a bare link AND a violation of the proposed rule? Yes, I've found a link with spaces in Markdown today and wasted some time checking why was raising MD034. Perhaps previous comment helps someone. Some more context, if you have a list of referenced links and the first has spaces, next links also raise MD034. [Online demo](https://dlaa.me/markdownlint/#%25m%23%20Header%0A%0ASome%20text%20with%20%5Blink%5D(link-1)%20and%20%5Banother%20link%5D%5Blink-2%5D.%0A%0A%5Blink-1%5D%3A%20https%3A%2F%2Furl%20with%20spaces%0A%5Blink-2%5D%3A%20https%3A%2F%2Furl-without-spaces%0A)
Author
Owner

@DavidAnson commented on GitHub (Aug 25, 2020):

In that most recent example, I don't think the reference links are all being recognized as such. Again, if CommonMark doesn't think it's a link (HTML content in the top right box), then this rule probably won't either.

<!-- gh-comment-id:680216580 --> @DavidAnson commented on GitHub (Aug 25, 2020): In that most recent example, I don't think the reference links are all being recognized as such. Again, if CommonMark doesn't think it's a link (HTML content in the top right box), then this rule probably won't either.
Author
Owner

@michael-hawker commented on GitHub (Mar 10, 2021):

Same applies for new-lines as well as spaces:

image

We accidently added a newline in a URL in our commit. 🤦‍♂️

It'd be great if the linter could detect this as a special case and call this out explicitly as a separate warning. "Newline in URL" or something. Because with the line wrapping in the PR it wasn't immediately obvious what was wrong here until you see "155 +".

<!-- gh-comment-id:794700337 --> @michael-hawker commented on GitHub (Mar 10, 2021): Same applies for new-lines as well as spaces: ![image](https://user-images.githubusercontent.com/24302614/110535332-fc584f00-80d4-11eb-854b-a540fab04c49.png) We accidently added a newline in a URL in our commit. 🤦‍♂️ It'd be great if the linter could detect this as a special case and call this out explicitly as a separate warning. "Newline in URL" or something. Because with the line wrapping in the PR it wasn't immediately obvious what was wrong here until you see "155 +".
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#245
No description provided.