Opened 14 years ago

Closed 14 years ago

#3941 closed defect (duplicate)

xhr formToQuery wrong url when multiple inputs have the same name.

Reported by: guest Owned by: anonymous
Priority: high Milestone: 1.0
Component: General Version: 0.9
Keywords: Cc:
Blocked By: Blocking:


xhr form handling code will not generate proper url when multiple inputs have the same name.

<input type="checkbox" checked name="multi2" value="bing">
<input type="checkbox" checked name="multi2" value="bong">

url will currently be multi2=bong while browser will generate multi2=bing&multi2=bong

the issue is further complicated by fact that current code uses object as an intermediate format and that url has no notion of array.
If we look object->form->object conversion for example:
both objects {"multi2": "bing"} and {"multi2": ["bing"]} will result in same query string multi2=bing .
it is obvious we can not convert this back to object, and code expecting array will break if url holds only one value.

php on server side has a simple naming convention to address this. For multiple values of a parameter:
if parameter name ends with "[]" an array will be created with all values, and "[]" will be stripped from parameter name,
if parameter name doesn't end with "[]" only last value will be used.

The issue goes even further because browser will handle any input with the same name this way, it will simply add the value to url as many times as the input appears.

I've created test case and patch for this issue addressing only checkbox because it is very common usage.

I'm have a version that follows mentioned php convention, but this may be unsuitable for some users.

I've sent a request for becomming a contributor, signed CLA also. alex could you spare some time and answer my email, am I not welcome ?. (sorry for using tracc for this.)

Attachments (1) (1.1 KB) - added by guest 14 years ago.
test case and patch

Download all attachments as: .zip

Change History (3)

Changed 14 years ago by guest

Attachment: added

test case and patch

comment:1 Changed 14 years ago by James Burke

Milestone: 1.0

comment:2 Changed 14 years ago by James Burke

Resolution: duplicate
Status: newclosed

This sounds like the same issue described in #4259, which has been fixed. So marking this a dupe (even though this bug was opened first), since the other ticket has the changeset with the fix.

I also suggest not attaching zip files, but uploading the individual files, if possible. Or, break out the fix patch from the test files if there are lots of test files. This will make it easier to evaluate the patch.

For becoming a contributor: see here for more info:

It sounds like you are starting the right way, filing tickets with patches. However, we will need to know who you are, so we can validate patches against a received CLA.

Note: See TracTickets for help on using tickets.