Fix UploadBase::checkXMLEncodingMissmatch() on PHP 7.1+
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 7 Jun 2018 00:54:07 +0000 (17:54 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 7 Jun 2018 03:13:13 +0000 (20:13 -0700)
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

RELEASE-NOTES-1.31
includes/upload/UploadBase.php
tests/phpunit/includes/upload/UploadBaseTest.php

index 49d53bd..c98f663 100644 (file)
@@ -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
index 27c0ed7..6a471ba 100644 (file)
@@ -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 ) ) {
index 3541091..a80262e 100644 (file)
@@ -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() {