# Links broken with (at least) two underscores in URL

**URL:** https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976
**Category:** Bug
**Created:** [October 28, 2017, 2:57pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976 "2017-10-28T14:57:02Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [October 28, 2017, 2:57pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/1 "2017-10-28T14:57:02Z")

</div>

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](https://twitter.com/_miss_ives_/status/923667180201414658)

  

Another example

`https://twitter.com/_FARTIGAS_/status/914070638561767425`  
[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 :

> **[UPDATE](https://www.sqlite.org/lang_update.html)**

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 28, 2017, 7:47pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/2 "2017-10-28T19:47:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [October 28, 2017, 8:01pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/3 "2017-10-28T20:01:33Z")

</div>

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](https://twitter.com/_miss_ives_/status/923667180201414658)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 28, 2017, 8:21pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/4 "2017-10-28T20:21:23Z")

</div>

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..

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [October 28, 2017, 9:02pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/5 "2017-10-28T21:02:49Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 28, 2017, 10:06pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/6 "2017-10-28T22:06:04Z")

</div>

@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](http://spec.commonmark.org/dingus/?text=https%3A%2F%2Ftwitter.com%2F_miss_ives_%2Fstatus%2F923667180201414658) @codinghorror

---

<div class="post-metadata">

### Author: ![Vitaly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vitaly/32/120475_2.png) [@Vitaly](https://meta.discourse.org/u/Vitaly)
#### Post date: [October 28, 2017, 11:28pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/7 "2017-10-28T23:28:30Z")

</div>

That’s a known issue:

[https://github.com/markdown-it/markdown-it/issues/38](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 `< >` 🙂

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [June 8, 2022, 2:19pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/8 "2022-06-08T14:19:32Z")

</div>

Could we fix this by doing the work in our _paste handler_, and if we’re pasting a URL, percent-encode underscores in the query string?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 8, 2022, 11:49pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/9 "2022-06-08T23:49:48Z")

</div>

Fiddling with clipboard is always something the will end in tears.

@Vitaly curious if you have had time to look at this issue recently? In this case it is the `https://...` linker.

I guess getting the ordering right in the engine and minimizing cost is a nightmare here.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 15, 2022, 6:38pm UTC](https://meta.discourse.org/t/links-broken-with-at-least-two-underscores-in-url/72976/10 "2022-06-15T18:38:29Z")

</div>

> [@sam](#):
>
> Fiddling with clipboard is always something the will end in tears.

I disagree; `https://` is SUCH a rare set of characters that I think fiddling is usually pretty safe.

(Except in code blocks, so there is this that, but if the clipboard is JUST AN URL, then it’s quite safe IMO. So if you did an anchor of “starts with `https://`” I can 99.99% guarantee it’ll be safe.)
