diff --git a/includes/libs/http/HttpAcceptParser.php b/includes/libs/http/HttpAcceptParser.php index 625237c6d39..625ad6ef9d5 100644 --- a/includes/libs/http/HttpAcceptParser.php +++ b/includes/libs/http/HttpAcceptParser.php @@ -40,7 +40,11 @@ class HttpAcceptParser { if ( isset( $matches[3] ) ) { $kvps = explode( ';', $matches[3] ); // FIXME: Allow semi-colon in quotes foreach ( $kvps as $kv ) { - [ $key, $val ] = explode( '=', trim( $kv ), 2 ); + $kvArray = explode( '=', trim( $kv ), 2 ); + if ( count( $kvArray ) != 2 ) { + continue; + } + [ $key, $val ] = $kvArray; $key = strtolower( trim( $key ) ); $val = trim( $val ); if ( $key === 'q' ) { diff --git a/tests/phpunit/unit/includes/libs/http/HttpAcceptParserTest.php b/tests/phpunit/unit/includes/libs/http/HttpAcceptParserTest.php index d930a8855e1..31089774340 100644 --- a/tests/phpunit/unit/includes/libs/http/HttpAcceptParserTest.php +++ b/tests/phpunit/unit/includes/libs/http/HttpAcceptParserTest.php @@ -139,6 +139,26 @@ class HttpAcceptParserTest extends TestCase { ] ] ], + [ + // Incomplete q - T391867 + 'test/123; q=0.5, test/789; q', + [ + [ + 'type' => 'test', + 'subtype' => '789', + 'q' => 1, + 'i' => 1, + 'params' => [] + ], + [ + 'type' => 'test', + 'subtype' => '123', + 'q' => 0.5, + 'i' => 0, + 'params' => [] + ], + ] + ], ]; }