Links produced by the Composer link modal break when they contain a ' (%27)

This is a bit of a weird little one, but highlights a problem with links in posts which are associated with text.

If I:

  1. create a data explorer query with a variable
  2. and assign it to a group
  3. visit the URL via the group’s reports tab
  4. add the variable and run the query
  5. copy the URL and add it to some text in a post

then the URL is corrupted / broken.

What I observe is:

  1. This is an example link thus created (private sorry):
    https://ehealthforum.nz/g/HiNZ-staff/reports/128?params=%7B%22topic_id%22%3A%2234521%22%7D
  2. When I add this link to some text here something goes screwy with the URL encoding and we get this:
    https://ehealthforum.nz/g/HiNZ-staff/reports/128?params=%257B%2522topic_id%2522%253A%252234521%2522%257D

And that beautifully breaks the site!

If I simply paste the link in the post, this doesn’t happen - it is only when I add it to text. So something goes funny when it encounters some existing encoding I think.

@nathank’s report focused on the specific niche thing they happened to be doing when they encountered the bug. However, the bug is in no way specific to Data Explorer. I fear the overly narrow focus of the report, and the use of the irrelevant data-explorer tag (the appropriate tag would be composer), might result in it being difficult for the Discourse team to interpret, or in it not being given the appropriate level of attention.

The fault occurs universally under the following conditions:

  • The URL contains percent-encoded content
  • The link is added to the post via the “Insert link” dialog.

The URL is always corrupted under these conditions.

Reproducible steps:

  1. Open the following URL in your web browser:
    https://en.wikipedia.org/wiki/Horncastle_boar%27s_head
    (note that the URL contains the ' character’s percent-encoding %27)
    :slightly_smiling_face: The expected page opens.
  2. Click the “Link” icon on the post composer.
    The “Insert link” dialog will open.
  3. Enter the above URL in the “Link or topic” field of the dialog.
  4. Click the “Insert” button.

:bug: The target of the link added through the above procedure is the incorrect:
https://en.wikipedia.org/wiki/Horncastle_boar%2527s_head

instead of the correct URL:
https://en.wikipedia.org/wiki/Horncastle_boar%27s_head

The link will not lead to the intended page.

This happened because the % character of the percent encoding %27 was encoded redundantly, causing the % to be replaced by its own percent-encoding %25, resulting in the correct URL content %27 being corrupted to %2527

Platform:

Operating System

  • Windows 11

Browser

  • Google Chrome 139.0.7258.128

Discourse

12c80d43adeb87cc18604ace0430a75d277d7662

Additional context:

I am able to reproduce the fault on try.discourse.org in “safe mode”.


The fault occurs in either composer mode.

2 Likes

OK, I can reproduce it, but exclusively when using the link modal, right? (Just to confirm the scope of the issue)

If I paste it directly: https://en.wikipedia.org/wiki/Horncastle_boar’s_head ; or paste the URL on top of a selection, it works as expected.

EDIT: Or… almost. The direct URL gets decoded: https://en.wikipedia.org/wiki/Horncastle_boar’s_head, which is also unexpected and avoids inline oneboxing.

Thank you for the report!

3 Likes

Yes, that is correct.

1 Like

Yes it did - I didn’t realise that it was a wider link encoding issue with the composer link modal.

I’ve edited the title and tag to reflect your good points and digging!

2 Likes