Fix PHP warning with some inputs to wfCgiToArray()

Also add some more tests for it.

Bug: T294017
Change-Id: I8a4faa42c2219ce415fbb82a248b07a28b59157d
This commit is contained in:
Bartosz Dziewoński 2021-10-21 20:49:34 +02:00
parent 24373dab6b
commit 2254eba8aa
2 changed files with 5 additions and 2 deletions

View file

@ -399,7 +399,7 @@ function wfCgiToArray( $query ) {
$k = substr( $k, 0, -1 ); $k = substr( $k, 0, -1 );
$temp = [ $k => $temp ]; $temp = [ $k => $temp ];
} }
if ( isset( $ret[$key] ) ) { if ( isset( $ret[$key] ) && is_array( $ret[$key] ) ) {
$ret[$key] = array_merge( $ret[$key], $temp ); $ret[$key] = array_merge( $ret[$key], $temp );
} else { } else {
$ret[$key] = $temp; $ret[$key] = $temp;

View file

@ -192,7 +192,8 @@ class GlobalTest extends MediaWikiIntegrationTestCase {
[ 'foo', [ 'foo' => '' ] ], // missing = [ 'foo', [ 'foo' => '' ] ], // missing =
[ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
[ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
[ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ], [ 'foo[bar]=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
[ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ], // urldecoding test 2
[ [
'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf', 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
[ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ] [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
@ -202,6 +203,8 @@ class GlobalTest extends MediaWikiIntegrationTestCase {
'foo%5Bbar%5D%5Bbar%5D=baz', 'foo%5Bbar%5D%5Bbar%5D=baz',
[ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ] [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
], ],
[ 'foo[]=x&foo[]=y', [ 'foo' => [ '' => 'y' ] ] ], // implicit keys are NOT handled like in PHP (bug?)
[ 'foo=x&foo[]=y', [ 'foo' => [ '' => 'y' ] ] ], // mixed value/array doesn't cause errors
]; ];
} }