Page MenuHomePhabricator

Use the correct algorithm when decoding URL hash fragments
Closed, ResolvedPublic

Description

Many places erroneously use decodeURI or decodeURIComponent, however these will throw an exception if they encounter a unencoded % which is allowed by the spec, e.g.

> decodeURIComponent('%A')
> Uncaught URIError: URI malformed

These errors have often just suppressed with a try/catch, and it is expected that fragments are generated fully encoded, however this is not always the case, and the escaping of user-generated inbound links is out of or control.

See also T106244

QA

The MobileFrontend Toggler ensures that if we link to a section of a page on mobile, the section gets automatically expanded. Note that opening the mobile site on a wide browser window will trigger "tablet mode" where sections are automatically expanded, so to test this you will need to open section links in a narrow browser window on the mobile site.

  1. Generate a link to a section of an article, e.g. by opening the site on desktop and copying a link from the table of contents
  2. Modify the link to be to mobile site
  3. Open the mobile link in a narrow window. Verify your section is scrolled to and the section opens.

Event Timeline

Change 823142 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/core@master] mediawiki.util: Add getTargetFromFragment (and percentDecode)

https://gerrit.wikimedia.org/r/823142

Change 823647 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/MobileFrontend@master] Toggler: Use upstream percentDecode

https://gerrit.wikimedia.org/r/823647

Change 823612 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/DiscussionTools@master] highlighter: Use upstream getTargetFromFragment

https://gerrit.wikimedia.org/r/823612

Change 825368 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Line number highlight: Use getTargetFromFragment

https://gerrit.wikimedia.org/r/825368

Change 823142 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.util: Add getTargetFromFragment (and percentDecode)

https://gerrit.wikimedia.org/r/823142

Change 823612 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@master] highlighter: Use upstream getTargetFromFragment

https://gerrit.wikimedia.org/r/823612

Change 825368 merged by jenkins-bot:

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Line number highlight: Use getTargetFromFragment

https://gerrit.wikimedia.org/r/825368

Olga: Incoming code review request from editing team for us (for https://gerrit.wikimedia.org/r/c/823647)

Given this impacts any URL containing a hash fragment we'll likely want to add some QA steps to this task before reviewing/merging.

Change 823647 merged by jenkins-bot:

[mediawiki/extensions/MobileFrontend@master] Toggler: Use upstream percentDecodeFragment

https://gerrit.wikimedia.org/r/823647

Esanders moved this task from Incoming to QA on the Editing-team (Kanban Board) board.
Esanders added a project: Editing QA.
Esanders moved this task from Inbox to High Priority on the Editing QA board.

Talked about this today in the editing team sync and editing team will be QAing this.

❗️ Verify your section is scrolled to and the section opens. The section with the % character does not open - Desktop and Mobile

@Esanders, I still get the warning when testing on https://en.wikipedia.beta.wmflabs.org/wiki/User:ESanders_(WMF)/sandbox#Romeo+Juliet_%A_%C3%93_%20.

Screenshot 2022-09-05 at 07.40.30.png (522×3 px, 277 KB)

See https://photos.app.goo.gl/8MNtRTUZbg7nH7sYA for more context

cc @matmarex

I think that's tracked separately: T315222: New vector TOC not escaping hash fragments and so generating invalid URLs. It should work in old Vector (and other skins).

The exceptions are real, but unrelated to our changes and pre-existing. Other code also doesn't handle these URLs well.

Thanks @matmarex.

This makes more sense to me now - it brought something else to my attention.
✅ Verify your section is scrolled to and the section opens

✔ This should be tested with headings with various character sets (e.g. Arabic, Thai). See https://photos.app.goo.gl/sVqEiv9JJKxzw3Ao8.

✔ Test this use case from a previous bug: https://en.wikipedia.beta.wmflabs.org/wiki/User:ESanders_(WMF)/sandbox#Romeo+Juliet_%A_%C3%93_%20 See

Screenshot 2022-09-07 at 07.39.32.png (688×424 px, 49 KB)

✔ Test that hash links on mobile with / still work, such as the link you get when the editor is open. See

Screenshot 2022-09-07 at 07.24.23.png (1×738 px, 129 KB)
and
Screenshot 2022-09-07 at 07.29.10.png (1×762 px, 122 KB)

ppelberg claimed this task.