Page MenuHomePhabricator

Replace UrlUtils::parse() and parse_url() with Uri\WhatWg\Url
Open, In Progress, Needs TriagePublic

Description

PHP's parse_url() implementation, and the MediaWiki helper UrlUtils::parse() that builds on it, have various inaccuracies compared to how browsers parse weird or malformed URLs. PHP 8.5 has Uri\WhatWg\Url which follows the same specification as modern browsers, and for older versions there's a polyfill. We should replace all calls.

Codesearch:

Event Timeline

Or maybe in the case of UrlUtils::parse(), it should just be updated to use the WhatWG compliant method. It would be a change in behavior, but probably only in cases where the old behavior was worse.

@Krinkle asked whether the Symfony polyfill already supports this (in which case we could avoid adding a new package), which is a good question but according to their list of supported features, it doesn't.

Dependency tree:

  • league/uri-polyfill
    • league/uri-interfaces (we already use it for oauth2-server)
    • rowbot/url
      • brick/math (which we already use for the various WebAuthn libraries)
      • rowbot/idna
        • symfony/polyfill-intl-normalizer (we already use it as part of some long Symfony dependency chain)
        • rowbot/punycode

Not too bad. The rowbot stuff is the actual spec logic, the polyfill package mostly just defines interfaces.

Another option is mensbeam/uri-polyfill. That one only depends on an intl package from the same author.
(The third used to be bakame-php/aide-uri but it was abandoned in favor of the league polyfill; searcging packagist and github didn't bring up further options).

Change #1328290 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/vendor@master] [POC] Add mensbeam/uri (WHATWG URI polyfill)

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

Change #1328295 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/vendor@master] [POC] Add league/uri-polyfill (WHATWG URI polyfill)

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

Tgr changed the task status from Open to In Progress.Sat, Aug 22, 2:29 PM
Tgr claimed this task.

Change #1328302 had a related patch set uploaded (by Gergő Tisza; author: tgr):

[mediawiki/core@master] [POC] Use WHATWG URI parsing

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