http: Handle accept header with incomplete q
When q is not followed by =, the array has not enough items and unpacking results in undefined array key. Also $val is set to null, resulting in php deprecation warning on trim() Bug: T391867 Change-Id: Ia5d4c9b6fb788ad4390d2562c6f38682f280a634 (cherry picked from commit cda46ed9f0c31280a8db59a2f0387e64e6308906)
This commit is contained in:
parent
f7a0d003c5
commit
723318ef91
2 changed files with 25 additions and 1 deletions
|
|
@ -40,7 +40,11 @@ class HttpAcceptParser {
|
||||||
if ( isset( $matches[3] ) ) {
|
if ( isset( $matches[3] ) ) {
|
||||||
$kvps = explode( ';', $matches[3] ); // FIXME: Allow semi-colon in quotes
|
$kvps = explode( ';', $matches[3] ); // FIXME: Allow semi-colon in quotes
|
||||||
foreach ( $kvps as $kv ) {
|
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 ) );
|
$key = strtolower( trim( $key ) );
|
||||||
$val = trim( $val );
|
$val = trim( $val );
|
||||||
if ( $key === 'q' ) {
|
if ( $key === 'q' ) {
|
||||||
|
|
|
||||||
|
|
@ -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' => []
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue