(bug 45069) wfParseUrl() no longer produces a PHP notice if passed a "mailto:" URL without address

Calling wfParseUrl( 'mailto:' ) or wfParseUrl( 'mailto:?subject=...' ) was resulting in the following PHP errors:
PHP Notice:  Undefined index: path in includes/GlobalFunctions.php on line 813
PHP Notice:  Undefined index: path in includes/GlobalFunctions.php on line 814

Now the existence of that key is checked and if missing an empty string is set so for consistency of the returned value.

The fix is based on the snippet provided on
https://www.mediawiki.org/wiki/Thread:Project:Support_desk/GLobafunctions.php_wfParseUrl_choking_on_url

Change-Id: Ife07d6e2a364a7cafda387cf7ed9cd71c2b68ef8
This commit is contained in:
Alexandre Emsenhuber 2013-02-18 13:17:23 +01:00
parent fba656f986
commit a7c103ad00
2 changed files with 10 additions and 3 deletions

View file

@ -169,6 +169,8 @@ production.
* (bug 43964) Invalid value of "link" parameter in <gallery> no longer produces * (bug 43964) Invalid value of "link" parameter in <gallery> no longer produces
a fatal error. a fatal error.
* (bug 44775) The username field is not pre-filled when creating an account. * (bug 44775) The username field is not pre-filled when creating an account.
* (bug 45069) wfParseUrl() no longer produces a PHP notice if passed a "mailto:"
URL without address
=== API changes in 1.21 === === API changes in 1.21 ===
* prop=revisions can now report the contentmodel and contentformat. * prop=revisions can now report the contentmodel and contentformat.

View file

@ -809,10 +809,15 @@ function wfParseUrl( $url ) {
if ( !isset( $bits['host'] ) ) { if ( !isset( $bits['host'] ) ) {
$bits['host'] = ''; $bits['host'] = '';
// bug 45069
if ( isset( $bits['path'] ) ) {
/* parse_url loses the third / for file:///c:/ urls (but not on variants) */ /* parse_url loses the third / for file:///c:/ urls (but not on variants) */
if ( substr( $bits['path'], 0, 1 ) !== '/' ) { if ( substr( $bits['path'], 0, 1 ) !== '/' ) {
$bits['path'] = '/' . $bits['path']; $bits['path'] = '/' . $bits['path'];
} }
} else {
$bits['path'] = '';
}
} }
// If the URL was protocol-relative, fix scheme and delimiter // If the URL was protocol-relative, fix scheme and delimiter