Links broken with (at least) two underscores in URL

AI-generated summary

A discussion is ongoing about broken links in Discourse when URLs contain at least two underscores. Steven shared examples of broken Twitter links with underscores, while codinghorror suggested using angle brackets to fix the issue, although this prevents oneboxing.

Steven found a temporary solution by replacing underscores with the URL-encoded version %5F. sam suggested reporting the issue to markdown.it for linkify, but Vitaly mentioned it’s a known issue with a workaround available.

sam asked if Vitaly has revisited the issue, and supermathie proposed fixing the issue by percent-encoding underscores in the query string in the paste handler. However, sam expressed concerns about fiddling with the clipboard. codinghorror disagreed, suggesting that fiddling with the clipboard is safe when dealing with URLs starting with https://.

i don’t know if this is an issue regarding Discourse exactly or if it’s coming from twitter API but I wanted to share this little bug, when we share a tweet from a account that has a underscore in its username, the link is broken on Discourse, here is an example :

https://twitter.com/_miss_ives_/status/923667180201414658
https://twitter.com/_miss_ives_/status/923667180201414658


Another example

https://twitter.com/_FARTIGAS_/status/914070638561767425
https://twitter.com/_FARTIGAS_/status/914070638561767425

when it’s not coming from twitter, a link with underscore works fine :

Put angle brackets on either side of the link. <like this>

That prevents oneboxing though. The link works, but it won’t onebox.
<https://twitter.com/_miss_ives_/status/923667180201414658>
https://twitter.com/_miss_ives_/status/923667180201414658

1개의 좋아요

Then it’s something @sam will have to add to his list for later. In the meantime, replace the underscore with the URL-encoded version of the character.

I’ll leave that as an excercise for the reader..

4개의 좋아요

It’s pretty rare so that’s not a hurry at all. No worry

I tried with %5F and works perfectly, that’ll do it nicely for now.

Thanks!

5개의 좋아요

@Vitaly Is this issue something you would like reported to markdown.it for linkify ?

( https://twitter.com/_miss_ives_/status/923667180201414658 not auto linking )

I am not sure we can even fix this properly cause we would have to push linkify forward in the pipeline?

Especially since this is default CommonMark http://spec.commonmark.org/dingus/?text=https%3A%2F%2Ftwitter.com%2F_miss_ives_%2Fstatus%2F923667180201414658 @codinghorror

That’s a known issue:

https://github.com/markdown-it/markdown-it/issues/38

It’s possible to fix, but not easy. Workaround available.

Correct solution is to make linkifier part of tokenizer process. That’s expensive (for example, email lookahead check for every character). Tradeoff is to listen : then do look behind for http(s), and lookahead for the rest. That’s not universal, but will cover all real cases:

  • http/https links will be parsed with other tokens, with higher priority than emphasis
  • everything else will be detected via text scan & regexps (as linkifier works now), probability of collision is very low.

I have no plans to do this, but if anyone wish to implement - see explanation above. Or use < > :slight_smile:

9개의 좋아요

붙여넣기 핸들러에서 작업을 처리하고, URL을 붙여넣는 경우 쿼리 문자열의 밑줄을 퍼센트 인코딩하는 방식으로 이 문제를 수정할 수 있을까요?

5개의 좋아요

클립보드 관련 작업을 하다 보면 결국 눈물만 나게 마련입니다.

@Vitaly, 최근 이 이슈를 확인해 보셨는지 궁금합니다. 이번에는 https://... 링크어와 관련된 문제입니다.

엔진에서 순서를 올바르게 설정하고 비용을 최소화하는 것이 여기서는 정말 악몽 같은 일이라고 생각합니다.

1개의 좋아요

동의하지 않습니다. https://는 매우 드문 문자열이라 클립보드 조작이 대체로 꽤 안전하다고 생각합니다.

(코드 블록을 제외하면요. 그래서 이 점은 있지만, 클립보드에 URL만 있는 경우라면 꽤 안전하다고 봅니다. 즉, https://로 시작하는 앵커를 만들면 99.99% 안전하다고 보증할 수 있습니다.)

1개의 좋아요