# Links with underbars surrounded by hyphens render incorrectly

**URL:** <https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913>\
**Category:** Bug\
**Created:** [September 24, 2018, 7:52am UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913 "2018-09-24T07:52:13Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

A rendering issue has been observed with automatic link detection in Discourse when links contain underbars (`_`) surrounded by hyphens (`-`). [mcwumbly](/t/-/97913/1) reports that the issue occurs with links like `https://example.org/foo-_bar_-baz`, causing incorrect rendering. A workaround is to use a real markdown link, such as `[foo _bar_ baz](https://example.org/foo-_bar_-baz)`. This issue has been previously observed in the context of linking to Twitter profiles with similar character patterns in usernames, as mentioned by [codinghorror](/t/-/97913/2).

<div class="post-metadata">

**Author:** ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)\
**Post date:** [September 24, 2018, 7:52am UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/1 "2018-09-24T07:52:13Z")

</div>

I’m not sure if this is a commonmark issue, a markdown-it issue, or a Discourse issue, but when sharing the link in [this post](https://meta.discourse.org/t/how-not-to-structure-your-database-backed-web-applications/97912), I noticed this edge case with the automatic link detection where the sequence `-_foo_-` breaks it.

This was the original link:

```plaintext
https://blog.acolyer.org/2018/06/28/how-_not_-to-structure-your-database-backed-web-applications-a-study-of-performance-bugs-in-the-wild/

```

Here’s a simplified example:

```plaintext
https://example.org/foo-_bar_-baz

```

And rendered:

[https://example.org/foo-\_bar\_-baz](https://example.org/foo-_bar_-baz)

(And as an image for good measure):

![link-detection-issue-edge-case](https://global.discourse-cdn.com/meta/original/3X/6/d/6d96acc9c13345b491ac847cfb5c083fe582bc41.png)

* * *

As a workaround, to make a link like this go to the right destination, you can always just use a _real_ markdown link like so:

```plaintext
[foo _bar_ baz](https://example.org/foo-_bar_-baz)

```

[foo _bar_ baz](https://example.org/foo-_bar_-baz)

---

<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:** [September 24, 2018, 3:05pm UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/2 "2018-09-24T15:05:53Z")

</div>

This was already opened in the context of a Twitter user with similar character patterns in username, rendering linking to that twitter profile very difficult.

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [September 24, 2018, 3:09pm UTC](https://meta.discourse.org/t/links-with-underbars-surrounded-by-hyphens-render-incorrectly/97913/3 "2018-09-24T15:09:06Z")

</div>

Closed on September 24, 2018, 3:09pm UTC

Known issue with commonmark, we can continue discussion here:

> [@Links broken with (at least) two underscores in URL](https://meta.discourse.org/t/twitter-links-broken-with-at-least-two-underscores-in-username/72976/7):
>
> That’s a known issue: 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 & r…
