Opened 10 years ago
Closed 9 years ago
#31306 closed defect (bug) (fixed)
add_query_arg changes numerical arguments
Reported by: | Lex_Robinson | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 4.1 |
Component: | General | Keywords: | has-patch commit |
Focuses: | Cc: |
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)
#4
@
10 years ago
- Milestone changed from Awaiting Review to 4.2
- Severity changed from minor to normal
This ticket was mentioned in Slack in #core by drew. View the logs.
9 years ago
#6
@
9 years ago
- Keywords commit added
31306.patch still applies, unit tests pass. Moving for commit consideration.
#8
@
9 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 31966:
Note: See
TracTickets for help on using
tickets.
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.