Opened 11 years ago
Closed 11 years ago
#31306 closed defect (bug) (fixed)
add_query_arg changes numerical arguments
| Reported by: | Lex_Robinson | Owned by: | wonderboymusic |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.2 |
| Component: | General | Version: | 4.1 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
I noticed this when I used '1=1' as a default query value to prevent a ? being prepended. If an argument passed to add_query_arg is a number, it gets replaced with an incrementing value. It doesn't re-order arguments or parse non-decimal numbers.
I suspect this is being caused by array_merge on line 782 of wp-includes/functions.php
var_dump( add_query_arg( array( 'foo' => 'bar' ), '1=1' ) ); // string '0=1&foo=bar' (length=11) var_dump( add_query_arg( array( 'a' => 'c' ), '1=1&a=b&10=10' ) ); // string '0=1&a=c&1=10' (length=12) var_dump( add_query_arg( array( '19' => '19' ), '20=20' ) ); // string '0=20&1=19' (length=9) var_dump( add_query_arg( array( '3e1' => '3' ), '0x1=1&a=b&010=2' ) ); // string '0x1=1&a=b&010=2&3e1=3' (length=21)
Attachments (1)
Change History (11)
This ticket was mentioned in Slack in #core by drew. View the logs.
11 years ago
#6
@
11 years ago
- Keywords commit added
31306.patch still applies, unit tests pass. Moving for commit consideration.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I was able to reproduce this issue, too.
And @Lex_Robinson, yes, your assumption is correct here -
array_merge()flattens the integer indexes. Replacing thatarray_merge()witharray_replace()will do the job, overriding what's necessary from the old query vars, but preserving the query vars with numeric keys.Patch coming up shortly.