Make WordPress Core

Ticket #44499: 44499.1.diff

File 44499.1.diff, 1.2 KB (added by costdev, 2 years ago)

Unit test added.

  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index b71a83761c..2417bcdf76 100644
    a b function add_query_arg( ...$args ) { 
    11691169        $ret = preg_replace( '#=(&|$)#', '$1', $ret );
    11701170        $ret = $protocol . $base . $ret . $frag;
    11711171        $ret = rtrim( $ret, '?' );
     1172        $ret = str_replace( '?#', '#', $ret );
    11721173        return $ret;
    11731174}
    11741175
  • tests/phpunit/tests/functions.php

    diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php
    index bcf8525216..4750bfcb9c 100644
    a b class Tests_Functions extends WP_UnitTestCase { 
    665665                $this->assertSame( 'foo=bar&1=2', $url );
    666666        }
    667667
     668        /**
     669         * Tests that add_query_arg removes the question mark when
     670         * a parameter is set to false.
     671         *
     672         * @ticket 44499
     673         *
     674         * @group add_query_arg
     675         *
     676         * @covers ::add_query_arg
     677         */
     678        public function test_add_query_arg_removes_question_mark() {
     679                $url      = 'http://example.org?param=value#anchor';
     680                $expected = 'http://example.org#anchor';
     681                $actual   = add_query_arg( 'param', false, $url );
     682                $this->assertSame( $expected, $actual );
     683        }
     684
    668685        /**
    669686         * @ticket 21594
    670687         */