From: daniel Date: Wed, 31 Oct 2012 19:16:36 +0000 (+0100) Subject: Fix handling of prot-rel URLs in SiteObject. X-Git-Tag: 1.31.0-rc.0~21795 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=4b436b70212bc301b271ffc47367d1cbc1ad9305 Fix handling of prot-rel URLs in SiteObject. Previously, getProtocol() would return null for a protocol relative URL, but the database field sites_protocol does not allow null as a value. Changed getProtocol() to return an empty string instead. Change-Id: I7e22cc3c3d8dca17a28fc4627083d5d2cb253887 --- diff --git a/includes/site/SiteObject.php b/includes/site/SiteObject.php index 6470c86e0d..adb2217e3e 100644 --- a/includes/site/SiteObject.php +++ b/includes/site/SiteObject.php @@ -157,10 +157,20 @@ class SiteObject extends ORMRow implements Site { $path = $this->getLinkPath(); if ( $path === false ) { - return false; + return ''; + } + + $protocol = parse_url( $path, PHP_URL_SCHEME ); + + if ( $protocol === false ) { // malformed URL + throw new MWException( "failed to parse URL $path" ); + } + + if ( $protocol === null ) { // no schema + $protocol = ''; // used for protocol relative URLs } - return parse_url( $path, PHP_URL_SCHEME ); + return $protocol; } /**