17

I added a comment to jQuery ID selector not working but something strange is happening. The end code reads "); but SO decided to change that to ";);.

screenshot

I did not add a ; in front of the ).

To further explain what's happening here, the following:

"http://example.com/." http://example.com/.
"http://example.com." http://example.com.
"http://example.com" http://example.com

renders as:

screenshot 2

14
  • 4
    Always write code between ` ` (backtick)
    – Alpine
    Commented Mar 19, 2011 at 13:18
  • $("img[id=Char_" + Character + "]").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d"); could not recreate
    – Alpine
    Commented Mar 19, 2011 at 13:21
  • $("img[id=Char_" + Character + "]").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d"); could not re-create with link
    – Alpine
    Commented Mar 19, 2011 at 13:28
  • @alpine Though I agree with you, some people don't have back tick on their keyboard. Can you reproduce this on the same post jao posted to, to make sure there aren't differences in comment markdown between meta and SO?
    – Pollyanna
    Commented Mar 19, 2011 at 13:39
  • @Adam Davis Yes, could not re-create on the same post
    – Alpine
    Commented Mar 19, 2011 at 14:23
  • @Adam There's a "code sample" button above the editor too Commented Mar 19, 2011 at 15:44
  • What i did was, I copied the string from the original post, then pasted it into the comment box (where it looked okay) $("img[id='Char_" + Character + "']").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d"); but now it does the same thing here. it probably is some funny character replacing thing
    – jao
    Commented Mar 19, 2011 at 15:49
  • 1
    @Michael We're talking about comments, and as far as I can see there's no buttons above the comment edit box...
    – Pollyanna
    Commented Mar 19, 2011 at 16:38
  • While I can't reproduce the issue with the given example line of code, it's easy to reproduce with balpha's example below: "http://xyz.com/a/b/c" --> "xyz.com/a/b/c" So the bug is valid, although users really should be putting code into backticks, as has been discussed before some users don't have backticks on their keyboard, and thus far Stack Exchange has chosen not to implement another method of adding code blocks into comments. It would seem that either Stack Exchange should fix this bug or add another method to delineate code blocks in comments.
    – Pollyanna
    Commented Mar 19, 2011 at 16:48
  • @adam define "some people don't have backtick on their keyboard". Maybe some people have no letters on their keyboard, either? Commented Jan 15, 2012 at 2:42
  • 1
    @JeffAtwood meta.stackexchange.com/questions/61235/…
    – Pollyanna
    Commented Jan 15, 2012 at 17:51
  • @AdamDavis. Use RFC 2606 domain names as examples.
    – TRiG
    Commented Jan 27, 2015 at 17:05
  • 4
    How on earth is this "by design"???? And it doesn't only affect code, but bog-standard links within English text. (meta.stackexchange.com/questions/252267/… et al) Commented May 2, 2015 at 14:58
  • Similar scenario happened to me, explained here: meta.stackexchange.com/q/300369/231145 Commented Aug 31, 2017 at 5:09

3 Answers 3

18

To explain what happens here:

"http://xyz.com/a/b/c"

is turned into

"http://xyz.com/a/b/c"

The auto-linker sees this as a link to http://xyz.com/a/b/c&quot, so the semicolon is left over, and that's where it suddenly appears from.

Granted, this is isn't exactly the expected result.

7
  • Interesting. "http://xyz.com/a/b/c" does show this issue: "xyz.com/a/b/c" It's odd that we can't reproduce it with his code line though...
    – Pollyanna
    Commented Mar 19, 2011 at 16:46
  • "xyz.com/a/b/c"
    – Alpine
    Commented Mar 19, 2011 at 16:51
  • "xyz.com/a/b/c"
    – Alpine
    Commented Mar 19, 2011 at 16:52
  • Now I can see ;
    – Alpine
    Commented Mar 19, 2011 at 16:53
  • $("img[id=Char_" + Character + "]").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d");
    – Alpine
    Commented Mar 19, 2011 at 16:55
  • Wouldn't it make sense to have the auto-linker not even try to create clickable links when the http part is not preceded with some whitespace? On the other hand, maybe punctuation such as preceding dots, commas, and... semicolons, still needs to be allowed then, as some don't properly type a space after those, like:example.com And when allowing those, the semi-colon in the preceding " would still trigger the auto-linking.
    – Arjan
    Commented Mar 3, 2012 at 13:45
  • Granted, this is isn't exactly the expected result. -> So maybe we could get rid of the status-bydesign and give it an deferred or planned? Commented Mar 11, 2018 at 18:18
1

I was able to reproduce it

We were trying

$("img[id=Char_" + Character + "]").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d");

But as jao said in the comments

What i did was, I copied the string from the original post, then pasted it into the comment box (where it looked okay) $("img[id='Char_" + Character + "']").attr("src", "image.xboxlive.com/global/t.584108a4/tile/0/2800d";); but now it does the same thing here. it probably is some funny character replacing thing – jao

The code that jao is copy / pasting is

$("img[id=Char_" + Character + "]").attr("src", "http://image.xboxlive.com/global/t.584108a4/tile/0/2800d");

As balpha demonstrated in an example

"http://xyz.com/a/b/c"

is turned into

"http://xyz.com/a/b/c"

The http:// in the link is the key

Try the code with http:// and see

0
1

This behavior is fixed, in that it is working better for all use cases but not perfect in your use case.

As balpha mentioned 7 years ago, the problem is that link extraction happens on HTML and the regular expression that handles it matches http://xyz.com/a/b/c&quot as a URL in http://xyz.com/a/b/c". This is because want trailing semicolons to be treated as punctuation.

I've made things a little smarter now in that:

  1. We never break up HTML entities when parsing URLs in rendered HTML.
  2. We unserialize trailing entities from matched strings and try re-evaluating them.
  3. We exclude trailing semicolons both before and after trailing entities.

Only trailing entities are considered because of other hacks that I was asked not to break.

The combination works nicely for URLs in quotes in lists. In your case, things are better in that the there's not a syntax error in your code, but not perfect because the ) prevents your " from being considered a trailing entity and puts it in the URL.

For code, it's still a best practice to wrap the whole thing in backticks, `, especially since the URL matcher strips off the protocol breaking the code in another way.

1

You must log in to answer this question.

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