Opened 2 years ago
Last modified 15 months ago
#17052 reopened defect (bug)
wp_sanitize_redirect() removes square brackets from URL
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | 3.1 |
| Severity: | minor | Keywords: | has-patch needs-testing |
| Cc: |
Description
The function wp_sanitize_redirect() removes square brackets from URLs.
PHP's functionality with arrays in the URL require square braces, stripping them from the URL means that pages (and plugins) that rely on them fail.
To Reproduce:
<?php $url = 'http://example.com/my_url_array[1]=hello+world'; print wp_sanitize_redirect($url); ?>
Current Output:
http://example.com/my_url_array1=hello+world
Expected Output:
http://example.com/my_url_array[1]=hello+world
Whilst developers should be able to work around this as the function is pluggable I believe this should just work out of the box.
Attachments (1)
Change History (6)
- Keywords has-patch removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
adds square braces to the regular expression for allowed characters in a safe URL
- Milestone set to Awaiting Review
- Resolution duplicate deleted
- Status changed from closed to reopened
Probably shouldnt've closed this so fast as a duplicate.
It's the same cause, but probably a lot better explained and in a different usecase.
- Keywords has-patch needs-testing added
Hi dd32,
Thanks for re-opening this ticket.
I was working under the assumption that the characters we simply missing from the regular expression due to an oversight.
It is a powerful feature to support.
If it is determined under review that they should be stripped from the URL, we can always automatically encode the square brackets into their entities inside the function.
Thanks for your time.
Jason
comment:5
SergeyBiryukov — 15 months ago
- Version changed from 3.4 to 3.1
Version number indicates when the bug was initially introduced/reported.

whilst referring to blogroll, the root cause is the same
In short, the brackets shouldn't be in the url, they *should* be encoded, but often arn't.
#16859