WordPress.org

Make WordPress Core

Changeset 31966


Ignore:
Timestamp:
04/01/2015 07:14:46 PM (5 years ago)
Author:
wonderboymusic
Message:

Respect numerical keys in add_query_arg(), use array_replace() instead of array_merge().

Adds unit test.

Props tyxla.
Fixes #31306.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r31891 r31966  
    783783    if ( is_array( $args[0] ) ) {
    784784        $kayvees = $args[0];
    785         $qs = array_merge( $qs, $kayvees );
     785        $qs = array_replace( $qs, $kayvees );
    786786    } else {
    787787        $qs[ $args[0] ] = $args[1];
  • trunk/tests/phpunit/tests/functions.php

    r31311 r31966  
    257257
    258258        $_SERVER['REQUEST_URI'] = $old_req_uri;
     259    }
     260
     261    /**
     262     * @ticket 31306
     263     */
     264    function test_add_query_arg_numeric_keys() {
     265        $url = add_query_arg( array( 'foo' => 'bar' ), '1=1' );
     266        $this->assertEquals('1=1&foo=bar', $url);
     267
     268        $url = add_query_arg( array( 'foo' => 'bar', '1' => '2' ), '1=1' );
     269        $this->assertEquals('1=2&foo=bar', $url);
     270
     271        $url = add_query_arg( array( '1' => '2' ), 'foo=bar' );
     272        $this->assertEquals('foo=bar&1=2', $url);
    259273    }
    260274
Note: See TracChangeset for help on using the changeset viewer.