WordPress.org

Make WordPress Core

Ticket #31306: 31306.patch

File 31306.patch, 1.2 KB (added by tyxla, 7 years ago)

Fixing the disappearance of numeric keys in add_query_arg(). Including a unit test.

  • src/wp-includes/functions.php

     
    782782        $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
    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];
    788788        }
  • tests/phpunit/tests/functions.php

     
    246246        }
    247247
    248248        /**
     249         * @ticket 31306
     250         */
     251        function test_add_query_arg_numeric_keys() {
     252                $url = add_query_arg( array( 'foo' => 'bar' ), '1=1' );
     253                $this->assertEquals('1=1&foo=bar', $url);
     254
     255                $url = add_query_arg( array( 'foo' => 'bar', '1' => '2' ), '1=1' );
     256                $this->assertEquals('1=2&foo=bar', $url);
     257
     258                $url = add_query_arg( array( '1' => '2' ), 'foo=bar' );
     259                $this->assertEquals('foo=bar&1=2', $url);
     260        }
     261
     262        /**
    249263         * @ticket 21594
    250264         */
    251265        function test_get_allowed_mime_types() {