9

Providing a new line as the first character of a URL in an inline link causes unexpected ouput.

Input

[Invalid](
http://www.example.com)

Expected Output

[Invalid]( http://www.example.com)

Or

Invalid

Note: While the first option is what is displayed in the non-preview version, it could be argued that the new line should be treated as whitespace and behave the same as [Invalid]( http://www.example.com) (the second option), in which case there's a bug in both the JavaScript preview and the non-preview version.

Actual Output

http://www.example.com">Invalid

Note: URL is not parsed into a link in actual output.

Live Output

[Invalid]( http://www.example.com)

Known Affected Browsers

Note: As so many different browsers are affected, this appears to not be a browser-specific issue, and is an issue with the markdown parser itself.

  • Firefox 11, 12
  • IE 8
  • Chromium 6
  • Chrome 19
  • Konqueror 4.4.5
6
  • 2
    Live Output looks like Expected Output for me, except in the editor preview, where it looks like Actual Output. Firefox 11 and 12.
    – user102937
    May 31, 2012 at 19:42
  • @RobertHarvey, yes, the preview is the main issue. However, as noted under Expected Output, it could be argued that the first expected output option is technically incorrect, as new lines should be treated just like spaces (which makes the non-preview version incorrect as well).
    – 0b10011
    May 31, 2012 at 19:45
  • Confirmed in IE8 (yes, some corporate environments still use it); again, only in the editor preview.
    – user102937
    May 31, 2012 at 19:47
  • Why are we confirming in browsers? Isn't this an issue with the Markdown parser? What do browsers have to do with anything?
    – animuson StaffMod
    May 31, 2012 at 19:48
  • @animuson, the main bug being reported is with the preview, which is client-side and could be browser-specific. Testing different browsers is to rule out a browser-specific bug.
    – 0b10011
    May 31, 2012 at 19:49
  • @Flimzy, missed that one. Will add. Anyway, this appears to not be a browser-specific issue, so we don't have to worry about that anymore.
    – 0b10011
    May 31, 2012 at 19:55

1 Answer 1

8

The link parser allowed too much whitespace in the URL, thus creating this:

<a href="\nhttp://link">Invalid</a>

The auto-linker saw "http://..." following a newline, and dutifully turned it into a link.

<a href="\n<a href="http://link">http://link</a>">Invalid</a>

Along came the HTML sanitizer, which takes everything from < to >, checks if it is a whitelisted HTML tag, and if not, removes it. Since <a href="\n<a href="http://link"> is not a whitelisted HTML tag by any strech of imagination, it was removed, leaving

http://link</a>">Invalid</a>

Finally the tag balancer kicks in, removing the two closing </a>s, since they don't have corresponding opening tags, leaving

http://link">Invalid

which is just what you saw. Fixed in the next build.

Regarding your suggestion of actually allowing the newline, like spaces, I don't really like that. It's a can of worms to allow these things to span multiple lines.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .