Page MenuHomePhabricator

wfParseUrl() fails for root-relative URLs
Open, Needs TriagePublic


While investigating T256831, I found that that this function fails for some relative urls just like the native parse_url().

Its documentation shows it exists to fix deficiencies of the native function (although some of these problems have been fixed in PHP since; see r608808), therefore it should work for all kind of relative urls; especially given the fact that WebRequest::getRequestURL() returns root-relative url (that will currently fail in wfParseUrl() )

// Protocol-relative URLs are handled really badly by parse_url(). It's so
// bad that the easiest way to handle them is to just prepend 'http:' and
// strip the protocol out later.
  $wasRelative = substr( $url, 0, 2 ) == '//';
    if ( $wasRelative ) {
     $url = "http:$url";

This work for protocol-relative urls, but doesn't for root-relative urls. So given Rest root-relative url, (fom T256831, for example)


wfParseUrl() will return false. This is because the function will pass it directly to parse_url() since the url will not match the $wasRelative check even though it's relative. The false itself is due to bug in parse_url() which this MediaWiki function implementation sought to ameliorate.

Event Timeline

Ammarpad created this task.Jul 1 2020, 7:31 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 1 2020, 7:31 PM
Ammarpad updated the task description. (Show Details)Jul 1 2020, 7:35 PM
Ammarpad renamed this task from wfParseUrl() fails for root-relative URL to wfParseUrl() fails for root-relative URLs.Jul 1 2020, 7:52 PM
Ammarpad updated the task description. (Show Details)