Respect numerical keys in add_query_arg()
, use array_replace()
instead of array_merge()
.
Adds unit test. Props tyxla. Fixes #31306. git-svn-id: https://develop.svn.wordpress.org/trunk@31966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
bcf98c7742
commit
d1235e323e
@ -782,7 +782,7 @@ function add_query_arg() {
|
||||
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
|
||||
if ( is_array( $args[0] ) ) {
|
||||
$kayvees = $args[0];
|
||||
$qs = array_merge( $qs, $kayvees );
|
||||
$qs = array_replace( $qs, $kayvees );
|
||||
} else {
|
||||
$qs[ $args[0] ] = $args[1];
|
||||
}
|
||||
|
@ -258,6 +258,20 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
$_SERVER['REQUEST_URI'] = $old_req_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31306
|
||||
*/
|
||||
function test_add_query_arg_numeric_keys() {
|
||||
$url = add_query_arg( array( 'foo' => 'bar' ), '1=1' );
|
||||
$this->assertEquals('1=1&foo=bar', $url);
|
||||
|
||||
$url = add_query_arg( array( 'foo' => 'bar', '1' => '2' ), '1=1' );
|
||||
$this->assertEquals('1=2&foo=bar', $url);
|
||||
|
||||
$url = add_query_arg( array( '1' => '2' ), 'foo=bar' );
|
||||
$this->assertEquals('foo=bar&1=2', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21594
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user