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 ) { |
1169 | 1169 | $ret = preg_replace( '#=(&|$)#', '$1', $ret ); |
1170 | 1170 | $ret = $protocol . $base . $ret . $frag; |
1171 | 1171 | $ret = rtrim( $ret, '?' ); |
| 1172 | $ret = str_replace( '?#', '#', $ret ); |
1172 | 1173 | return $ret; |
1173 | 1174 | } |
1174 | 1175 | |
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 { |
665 | 665 | $this->assertSame( 'foo=bar&1=2', $url ); |
666 | 666 | } |
667 | 667 | |
| 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 | |
668 | 685 | /** |
669 | 686 | * @ticket 21594 |
670 | 687 | */ |