Commit graph

4 commits

Author SHA1 Message Date
Petr Pchelko
5ad8ee4d92 Follow RFC 3986 on what is path in mailto URLs
This hack was originally added to wfParseUrl
as a fix for T10324 specifically for LinkFilter,
however according to the RFC 3986 this is wrong.

RFC defines that in URLs the authority component
must start with //, so in urls without //, e.g. news:
or mailto: there is no authority component, and thus
no host component, everything after : is actually a path,
so default PHP parse_url is correct.

RFC even has an example:
> For example, the URI <mailto:fred@example.com>
has a path of "fred@example.com".

It's fairly ugly to just copy-paste the hack
into LinkFilter, but I didn't find an easy and
elegant way to rewrite it without making any
changes to the link indexes values stored in the DB.

See https://datatracker.ietf.org/doc/html/rfc3986

Co-Authored-by: 沈澄心 <dringsim@qq.com>
Change-Id: I3dd04495db9c7a66f62c3914c0eff06754b7d560
2023-09-04 05:48:23 +00:00
Timo Tijhof
b862174dc0 UrlUtils: Make assemble() and removeDotSegments() stateless
Follows-up 472a914c63 (I706ef8a50aafb51), which moved various
functions here en-mass, but these two don't require any state.

The warnings about parse_url() in UrlUtils.php have been obsolete
since about PHP 5.4, when it started to support protocol-relative
URLs, non-slash protocols like "mailto", and deal with spaces/newlines
correctly (https://3v4l.org/YWUkl).

Rather than complicate many components that would otherwise remain
stateless and unit-testable, fix these to once again be the static
functions they were.

For impact, see upto PS17 of change I5117eab95f57297eb02bed.

Bug: T227900
Change-Id: Ifb3f720fc429b107348644c98eb9cd8e1113a42a
2023-08-10 03:39:42 +01:00
Tim Starling
363adf7df4 Fix silently skipped UrlUtilsTest
phpunit --filter UrlUtilsTest would execute no tests because the class
was already loaded by the GlobalFunctions data providers via the
autoloader, so PHPUnit sees no additional classes when it examines
UrlUtilsTest.php.

So, split out all providers in UrlUtilsTest to a separate class which
can be safely autoloaded.

Change-Id: I483736ee70e598cdb19f8203bc6885f1c234fc42
2022-05-16 14:01:22 +10:00
Aryeh Gregor
472a914c63 Refactor URL-parsing global functions to class
The new class, UrlUtils, is usable standalone or as a service. Using it
as a service will just automatically load a few settings from site
configuration.

In addition to just making our code cleaner, this will enable making
some of Setup.php's dynamic configuration more sane.

Test coverage is all lines except invalid URLs -- I couldn't find any.

Bug: T305093
Change-Id: I706ef8a50aafb518e13222719575d274c3583b90
2022-04-12 15:14:35 +03:00