Opened 13 years ago
Closed 13 years ago
#20143 closed defect (bug) (fixed)
Array query args on a paginated archive page creates PHP Warning, breaks page.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | Canonical | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
Having query args that are elements of an array breaks in redirect_canonical.
To reproduce:
- Create enough posts in an install to warrant pagination of posts
- Go to second page and add an array element query arg eg. http://www.siteurl.com/page/2/?foo[bar]=true
I'm getting this PHP warning:
Warning: rawurlencode() expects parameter 1 to be string, array given in /Users/ericlewis/Sites/wp-trunk/wp-includes/canonical.php on line 283 Warning: Cannot modify header information - headers already sent by (output started at /Users/ericlewis/Sites/wp-trunk/wp-includes/canonical.php:283) in /Users/ericlewis/Sites/wp-trunk/wp-includes/pluggable.php on line 864
This stems from the fact that in redirect_canonical, the query args are parsed into an array via parse_str(), and then rawurlencode() is applied to each element of that array. In this case, that means rawurlencode is applied to an array (foo), which causes the issue.
Attachments (3)
Change History (10)
#2
@
13 years ago
- Cc toppa added
I just uploaded a revised version with a correction to my code.
This problem is affecting one of our projects. We're doing taxonomy and meta filtering based on form submissions that have checkboxes using arrays. My patch fixes the pagination problem we're experiencing.
#3
@
13 years ago
- Component changed from General to Canonical
- Keywords has-patch added
- Milestone changed from Awaiting Review to 3.4
when you upload a new version of the patch, don't overwrite the old one, it's simpler to track changes/etc.
changes look sane, although do we really need to use the wrapping function around the url decode?
#4
@
13 years ago
Thanks - I'll not overwrite next time (this is my first patch). If you try to call rawurlencode without the wrapping function you will get a PHP warning. array_walk_recursive wants the function you give it to take 2 parameters (value and key).
#6
@
13 years ago
- Keywords needs-unit-tests added
The cognitive problem with array_walk() is that it requires a callback that is particular to its use, as it needs to accept two particular arguments. This is not the case with array_map(). For when the callback does not require the key to operate, it is nicer, as you can do things like using intval, absint, or whatever else you might have. Or, in this case, rawurlencode().
Since we already have urlencode_deep(), I figure we can just add a rawurlencode_deep(). See 20143.diff. Still props toppa and Sergey for the docs as the approach is the same.
I replaced array_map on line 283 with array_walk_recursive and added a rawurlencode callback function. I put the callback function at the bottom of the file - there may be a better place for it.