diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index fbe1219866..42f6873b64 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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]; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 527780ae27..4d3a4bbdd5 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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 */