2

Possible Duplicate:
Hyperlink is shown incorrectly in SO post

In the preview, the link below is displayed correctly (but is incomplete).
After posting, it does not work any more. The brackets need to be encoded.

[Link][1]

This is related to Hyperlink is shown incorrectly in SO post.

My question is: Why is this incorrect URL handled different by the preview?

[1]: http://download.oracle.com/javase/6/docs/api/java/util/logging/Logger.html#Logger(java.lang.String, java.lang.String)

2

2 Answers 2

2

This is fixed now; your post will look identical in the preview and in the final version after the next build.

2

According to the specification, the rules for the second part of your link are as followed (emphasis mine):

  • Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces);
  • followed by a colon;
  • followed by one or more spaces (or tabs);
  • followed by the URL for the link;
  • optionally followed by a title attribute for the link, enclosed in double or single quotes, or enclosed in parentheses.

So, under no circumstance would your link be interpreted fully without being properly encoded, but the part in parentheses should be considered the optional title attribute of the link based on this text.

However, the original Perl implementation (and by association, the C# implementation used by SO) both have a lookbehind for whitespace preceding the title. While the above description never mentions this being required whitespace, all of the examples have it, so we'll assume that it's actually necessary.

Since JavaScript regular expressions don't support lookbehinds, the expression used on the client side just drops the part that makes the whitespace required, so the parenthetical part of your URL is interpreted as the optional title attribute incorrectly.

I believe that it would be possible to correct the client-side code by swapping out the occurrences of this regular expression excerpt in stripLinkDefs:

[ \t]*\n?[ \t]*

...for this one:

(?:[ \t]*\n[ \t]*|[ \t]+)

That way, you'd have to at least have either the newline or a tab/space before the parenthesis for the preview to display what you were seeing originally, which I think is consistent with how the server handles it.

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