From: Kunal Mehta Date: Thu, 7 Jun 2018 00:54:07 +0000 (-0700) Subject: Fix UploadBase::checkXMLEncodingMissmatch() on PHP 7.1+ X-Git-Tag: 1.34.0-rc.0~5168^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=827cfb3351db57332e16db48bdfbcde6131c17cd Fix UploadBase::checkXMLEncodingMissmatch() on PHP 7.1+ file_get_contents() started supporting a negative offset in 7.1+. But we really just want to start with 0. Also fix the order of arguments to assertSame() so that the expected value is first. Bug: T182366 Change-Id: I84c92652de5b51a43f6e2b58cd235d2889093453 --- diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index 49d53bd398..c98f6633ef 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -10,6 +10,7 @@ production. * (T196092) Hide MySQL binary/utf-8 charset option in the installer. * (T196185) Don't allow setting $wgDBmysql5 in the installer. * (T196125) php-memcached 3.0 (provided with PHP 7.0) is now supported. +* (T182366) UploadBase::checkXMLEncodingMissmatch() now works on PHP 7.1+ === Changes since MediaWiki 1.31.0-rc.0 === * (T33223) Drop archive.ar_text and ar_flags. @@ -166,6 +167,7 @@ production. * (T2087, T10897, T87753, T174639) Whitespace created by category and language links is now stripped rather than leaving blank lines in odd places. * (T3780) Uploads with UTF-8 names now work on PHP7.1+ on Windows servers. +* (T182366) UploadBase::checkXMLEncodingMissmatch() now works on PHP 7.1+ === Action API changes in 1.31 === * (T185058) The 'name' value to tgprop for action=query&list=tags has been diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 27c0ed7730..6a471ba573 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1397,7 +1397,7 @@ abstract class UploadBase { */ public static function checkXMLEncodingMissmatch( $file ) { global $wgSVGMetadataCutoff; - $contents = file_get_contents( $file, false, null, -1, $wgSVGMetadataCutoff ); + $contents = file_get_contents( $file, false, null, 0, $wgSVGMetadataCutoff ); $encodingRegex = '!encoding[ \t\n\r]*=[ \t\n\r]*[\'"](.*?)[\'"]!si'; if ( preg_match( "!<\?xml\b(.*?)\?>!si", $contents, $matches ) ) { diff --git a/tests/phpunit/includes/upload/UploadBaseTest.php b/tests/phpunit/includes/upload/UploadBaseTest.php index 3541091a68..a80262e932 100644 --- a/tests/phpunit/includes/upload/UploadBaseTest.php +++ b/tests/phpunit/includes/upload/UploadBaseTest.php @@ -562,7 +562,7 @@ class UploadBaseTest extends MediaWikiTestCase { public function testCheckXMLEncodingMissmatch( $fileContents, $evil ) { $filename = $this->getNewTempFile(); file_put_contents( $filename, $fileContents ); - $this->assertSame( UploadBase::checkXMLEncodingMissmatch( $filename ), $evil ); + $this->assertSame( $evil, UploadBase::checkXMLEncodingMissmatch( $filename ) ); } public function provideCheckXMLEncodingMissmatch() {