What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

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)

share|improve this question

marked as duplicate by balpha Jan 6 '11 at 11:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
See this related bug report –  Tim Stone Jan 4 '11 at 8:05
    
@TimStone: Thanks, just saw that under the Related posts. Unfortunately, I could not find it before... –  Peter Lang Jan 4 '11 at 8:06

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer

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.

share|improve this answer

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