# One Box url encoding of already encoded comma

**URL:** <https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912>\
**Category:** Bug\
**Created:** [June 20, 2019, 1:59pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912 "2019-06-20T13:59:56Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

A bug was reported where Discourse's One Box feature incorrectly double-encodes URLs that already contain encoded characters, such as commas. [Robinio](/t/-/120912/1) demonstrated that a URL containing `%2C` (encoded comma) was transformed into `%252C`, effectively encoding the percent sign itself. Robinio noted that while ampersands were handled correctly in a previous fix, commas were not, and suggested that already-encoded characters should not be re-encoded. [codinghorror](/t/-/120912/2) flagged the issue for investigation by [techAPJ](/t/-/120912/4). Additionally, [Mittineague](/t/-/120912/3) reported a similar issue involving double-encoded apostrophes in Wikipedia links. The issue was resolved by [techAPJ](/t/-/120912/4) via a commit to the Discourse Onebox repository, fixing the encoding logic to prevent double-encoding of existing encoded sequences.

<div class="post-metadata">

**Author:** ![Robinio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/robinio/32/147333_2.png) [@Robinio](https://meta.discourse.org/u/Robinio)\
**Post date:** [June 20, 2019, 1:59pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912/1 "2019-06-20T13:59:56Z")

</div>

There seems to have been a recent change in Discourse with One Box url encoding.

I run a website that generates links like: `www.discourse.org/?a=a%2Cb` where `%2C` is the encoded version of the comma. If I paste this link to a one box:

> **[Where Tech Companies Build Communities](https://www.discourse.org/?a=a%2Cb)**
>
> The customizable, scalable community platform powering over 22,000 communities. Create knowledge through conversation.

The generated link is:

`https://www.discourse.org/?a=a%252Cb`

The encoded comma became `%252C`.

If you run `encodeURIComponent(encodeURIComponent(','))` the result is `%252C`. IMHO the correct behavior would be not to encode already encoded characters. For example the ampersand works correctly with the latest discourse ([https://meta.discourse.org/t/onebox-incorrectly-encodes-urls-with-ampersands/61542](https://meta.discourse.org/t/onebox-incorrectly-encodes-urls-with-ampersands/61542)).

---

<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 20, 2019, 2:01pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912/2 "2019-06-20T14:01:12Z")

</div>

Is this a new bug @techAPJ?

---

<div class="post-metadata">

**Author:** ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)\
**Post date:** [June 20, 2019, 8:31pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912/4 "2019-06-20T20:31:08Z")

</div>

I had a similar “doubly encoded apostrophe” happen 15 days ago. i.e.

> **[Henry's pocket](https://en.wikipedia.org/wiki/Henry's_pocket)**
>
> In animal anatomy, Henry's pocket, more formally known as a cutaneous marginal pouch, is a fold of skin forming an open pouch on the lower posterior part of the external ear. The pocket is situated in the approximate location of the antitragus in the human ear. It occurs in a number of mammalian species, including weasels and bats, but is particularly noticeable on the domestic cat, as well as some dog breeds.
> It is unknown where the name "Henry's pocket" came from. The earliest known use of the...

as  
`https://en.m.wikipedia.org/wiki/Henry%27s_pocket`

while using Brave

---

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [June 27, 2019, 5:44pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912/5 "2019-06-27T17:44:20Z")

</div>

Fixed via:

[https://github.com/discourse/onebox/commit/ce35d518aaac8d0b29d56e176af35d75f86b41e6](https://github.com/discourse/onebox/commit/ce35d518aaac8d0b29d56e176af35d75f86b41e6)

Thanks for reporting this issue @Robinio 👍

---

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [June 27, 2019, 6:05pm UTC](https://meta.discourse.org/t/one-box-url-encoding-of-already-encoded-comma/120912/6 "2019-06-27T18:05:52Z")

</div>

Closed on June 27, 2019, 6:05pm UTC


