This link works fine when it's copy/pasted:


But the _ gets encoded as %5f when it's autolinked, and this can break the URL:


Edit: Admittedly, the issue is related to GitHub in this case:

$ curl -I "https://github.com/cyga/www%5ffdw/"
HTTP/1.1 404 Not Found
Server: GitHub.com
Date: Mon, 14 Apr 2014 13:42:08 GMT
Content-Type: text/html; charset=utf-8
Status: 404 Not Found
Cache-Control: no-cache
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Length: 226672
X-GitHub-Request-Id: 5062C074:7D81:1D8C557:534BE5AF
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff

But Stack Overflow could work around the problem by not encoding the _ character to begin with.

  • 6
    No, encoding _ to %5f would not break a URL; it merely uses a standard encoding scheme. The hyperlink works just fine. – Martijn Pieters Apr 14 '14 at 13:34
  • 2
    @MartijnPieters: I get a 404 error when I visit the linked page. (Safari on OSX) – Denis de Bernardy Apr 14 '14 at 13:37
  • 2
    I'm getting a 404 on the hyperlink (Firefox on Windows 7). – Bill the Lizard Apr 14 '14 at 13:38
  • @Bart: I'm merely pasting the URL from the Safari address bar. If I click the resulting link, it's a 404. – Denis de Bernardy Apr 14 '14 at 13:39
  • @Denis: it works fine for me in Chrome, but can indeed reproduce the problem in Safari. – Martijn Pieters Apr 14 '14 at 13:39
  • @MartijnPieters: so it is a bug indeed. Perhaps not one that is due to SO itself, but certainly one that SO can work around by not encoding the _ character. – Denis de Bernardy Apr 14 '14 at 13:40
  • 1
    This could also be construed as a Github problem; they fail to decode the URL encoding correctly, it appears. The URL is certainly perfectly valid according to the RFC. Chrome normalizes the URL, heading off the issue. – Martijn Pieters Apr 14 '14 at 13:40
  • 1
    To quote the Wikipedia article: URIs that differ only by whether an unreserved character is percent-encoded or appears literally are equivalent by definition, but it points out some processors may not handle these correctly. _ is not a reserved character, but my guess is that Stack Exchange escapes it to prevent it from being interpreted as Markdown. – Martijn Pieters Apr 14 '14 at 13:43
  • 1
    @MartijnPieters: Sure it's valid per the RFC. What difference does this make if the URL is broken when you try it? I've reported the bug to Github, but I'm sure there are plenty of other sites with the same kind of problems. And the question remains at the end of the day: Is there any good reason for SO to be encoding underscores in URLs like that. – Denis de Bernardy Apr 14 '14 at 13:47
  • 4
    @Denis: It's a fine line to walk between not triggering a problem and fixing the problem at the source. If sites don't handle percent-encoded characters in the URI correctly then that's a bug with that site. I suspect that the rewritten markdown emphasis / strong handling has something to do with all this. – Martijn Pieters Apr 14 '14 at 13:52
  • See meta.stackexchange.com/a/229144/161198 – Bart Apr 14 '14 at 13:53

Fair enough. If even GitHub gets this wrong, then there'll probably be a big bunch of other sites that do as well. And when revisiting, percent-encoding wasn't the optimal solution anyway to fix this bug.

I'll deploy this right away; change should be available in a couple of minutes.

| improve this answer | |

You must log in to answer this question.

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