WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#18814 new enhancement

wp_redirect wont allow arrays to be sent in query string

Reported by: jacksplay Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.2.1
Component: General Keywords:
Focuses: Cc:

Description

The pluggable function wp-redirect will not allow arrays to be sent in a query string.

ie: http://www.example.com/?array[]=first&array[]=second&array[]=last

The brackets are stripped out when the URL is sanitized and it becomes:

http://www.example.com/?array=first&array=second&array=last

This removes the ability to pass the array.

Change History (2)

comment:1 nacin3 years ago

  • Type changed from defect (bug) to enhancement

Brackets are reserved characters for enclosing IP literals. They should be encoded when used elsewhere. Encoding them on our own is something we don't currently do, and changing it may possibly have backwards compatibility issues. See also #10281.

One thought might be to automatically encode [], together, to allow general array passing, and only if it appears in the query string.

comment:2 jacksplay3 years ago

Just to update for other users searching about this issue.

You will need to encode this when sending an array to another script or in my case I needed to send a link in an email with the array.

$query = "array[]=first&array[]=second&array[]=last";
$query =str_replace(array('[',']'), array('%5B','%5D'), $query);
wp_redirect("http://www.example.com/?$query",302);

url_encode() will not encode the brackets because the square bracket is allowed in a URI.

Last edited 3 years ago by jacksplay (previous) (diff)
Note: See TracTickets for help on using tickets.