Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
— | — | @@ -96,9 +96,9 @@ |
97 | 97 | |
98 | 98 | function testArrayToCGI() { |
99 | 99 | $this->assertEquals( |
100 | | - "baz=AT%26T&foo=bar", |
| 100 | + "baz=AT%26T&empty=&true=1&foo=bar", |
101 | 101 | wfArrayToCGI( |
102 | | - array( 'baz' => 'AT&T', 'ignore' => '' ), |
| 102 | + array( 'baz' => 'AT&T', 'empty' => '', 'ignored' => null, 'ignored2' => false, 'true' => true ), |
103 | 103 | array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) ); |
104 | 104 | $this->assertEquals( |
105 | 105 | "path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost", |
— | — | @@ -110,8 +110,9 @@ |
111 | 111 | function testCgiToArray() { |
112 | 112 | $this->assertEquals( |
113 | 113 | array( 'path' => array( 'wiki', 'test' ), |
114 | | - 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ), |
115 | | - wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost' ) ); |
| 114 | + 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ), |
| 115 | + 'qwerty' => '' ), |
| 116 | + wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost&qwerty' ) ); |
116 | 117 | } |
117 | 118 | |
118 | 119 | function testMimeTypeMatch() { |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | /** |
324 | 324 | * This function takes two arrays as input, and returns a CGI-style string, e.g. |
325 | 325 | * "days=7&limit=100". Options in the first array override options in the second. |
326 | | - * Options set to "" will not be output. |
| 326 | + * Options set to null or false will not be output. |
327 | 327 | * |
328 | 328 | * @param $array1 Array ( String|Array ) |
329 | 329 | * @param $array2 Array ( String|Array ) |
— | — | @@ -336,7 +336,7 @@ |
337 | 337 | |
338 | 338 | $cgi = ''; |
339 | 339 | foreach ( $array1 as $key => $value ) { |
340 | | - if ( $value !== '' ) { |
| 340 | + if ( !is_null($value) && $value !== false ) { |
341 | 341 | if ( $cgi != '' ) { |
342 | 342 | $cgi .= '&'; |
343 | 343 | } |
— | — | @@ -369,8 +369,7 @@ |
370 | 370 | * This is the logical opposite of wfArrayToCGI(): it accepts a query string as |
371 | 371 | * its argument and returns the same string in array form. This allows compa- |
372 | 372 | * tibility with legacy functions that accept raw query strings instead of nice |
373 | | - * arrays. Of course, keys and values are urldecode()d. Don't try passing in- |
374 | | - * valid query strings, or it will explode. |
| 373 | + * arrays. Of course, keys and values are urldecode()d. |
375 | 374 | * |
376 | 375 | * @param $query String: query string |
377 | 376 | * @return array Array version of input |
— | — | @@ -385,7 +384,13 @@ |
386 | 385 | if ( $bit === '' ) { |
387 | 386 | continue; |
388 | 387 | } |
389 | | - list( $key, $value ) = explode( '=', $bit ); |
| 388 | + if ( strpos( $bit, '=' ) === false ) { |
| 389 | + // Pieces like &qwerty become 'qwerty' => '' (at least this is what php does) |
| 390 | + $key = $bit; |
| 391 | + $value = ''; |
| 392 | + } else { |
| 393 | + list( $key, $value ) = explode( '=', $bit ); |
| 394 | + } |
390 | 395 | $key = urldecode( $key ); |
391 | 396 | $value = urldecode( $value ); |
392 | 397 | if ( strpos( $key, '[' ) !== false ) { |