Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#63462 new defect (bug)

add_query_arg() should handle encoded input URLs

Reported by: kkmuffme's profile kkmuffme Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: Cc:

Description

When passing an already encoded URL to add_query_arg, it will make existing query args after # to be an anchor.
Since add_query_arg expects URL encoded params for key/value, people often assume this is the case for the URL too - that results in an unexpected result though.
Especially since it says:

Values are expected to be encoded appropriately with urlencode() or rawurlencode().

and

$value Optional. Either a query variable value, or a URL to act upon.

<?php
echo add_query_arg('foo', 'bar', '/wp-admin/admin.php?page=hello&#038;tab=world&#038;abc=xyz' );

will result in

'/wp-admin/admin.php?page=hello&foo=bar#038;tab=world&#038;abc=xyz'

I guess add_query_arg should either add a "doing it wrong" when passing an encoded URL or automatically, correctly handle encoded URLs.

Change History (1)

This ticket was mentioned in PR #8817 on WordPress/wordpress-develop by @sainathpoojary.


5 weeks ago
#1

  • Keywords has-patch added

Trac ticket: #63462

Note: See TracTickets for help on using tickets.