Closed Jayshua closed 1 year ago
Thanks, looks like we hadn't expected/thought of numeric query params when implementing the logic.
@lukasbestle I've looked into issue. I've found the source of issue. This issue is coming from following line:
As as solution, I think we need to use array_replace
instead array_merge
. I've tested and seems works great. But I'm not sure if this change will break anything. What do you think?
array_merge documentation: values in the input arrays with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
The only difference between array_merge()
and array_replace()
that I'm aware of is the handling of numeric keys. Since we want PHP to treat keys as strings, not as numbers, array_replace()
is indeed the correct choice here IMO.
Description
When submitting a form using numeric field names like
<input name="1"><input name="0">
the browser submits the form data in url encoded format like1=first+value&0=second+value
. Theget
helper, when called likeget(1)
or with a string likeget('1')
, will retrieve the value at index 1 in the encoded string ('second+value' in this example) rather than with key 1 ('first+value' in this example).Expected behavior I expected
get
to retrieve by key rather than by index, matching PHP's behavior when using$_POST
.My Diagnosis
\Kirby\Http\Request::data()
callsarray_merge
to combine the body and query param data into a single data array.array_merge
is documented to renumber numeric keys. I believedata
should callarray_replace
instead, which combines the arrays without renumbering them.To reproduce
Replace index.php with:
Submit a POST request in the standard
application/x-www-form-urlencoded
format. Here are some examples:1=first+value&0=second+value
0=second+value&1=first+value
Your setup
Kirby Version: 3.9.2