You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Alexander Shorin (JIRA)" <ji...@apache.org> on 2013/07/16 16:58:48 UTC

[jira] [Commented] (COUCHDB-1855) POST/GET query is not processing arrays properly

    [ https://issues.apache.org/jira/browse/COUCHDB-1855?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13709827#comment-13709827 ] 

Alexander Shorin commented on COUCHDB-1855:
-------------------------------------------

Yes, there is no actual standard, so implementation may choose his own way to handle multiple values for the same parameter: take first, take last, make an array.

As for me with some PHP background, I'd like let last one wins for case:

{code}
http://localhost:5984/db/_design/blog/_list/index/posts?author=Mike&author=John
{code}

If I'd like to handle multiple values of the author parameter, I want to have it explicitly defined in the query:

{code}
http://localhost:5984/db/_design/blog/_list/index/posts?author[]=Mike&author[]=John
{code}

But still, probably this one I like much more:

{code}
http://localhost:5984/db/_design/blog/_list/index/posts?author=["Mike", "John"]
{code}

Btw, some interesting link about:
- [HTTP Parameter Pollution|https://www.owasp.org/images/b/ba/AppsecEU09_CarettoniDiPaola_v0.8.pdf]
                
> POST/GET query is not processing arrays properly
> ------------------------------------------------
>
>                 Key: COUCHDB-1855
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1855
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>            Reporter: Andrew Spode Miller
>            Priority: Minor
>
> Sending an array in POST/GET url encoded form is not working correctly.
> For example:
> ?foo[]=bar&foo[]=bar2
> OR
> ?foo[0]=bar&foo[1]=bar2
> OR 
> ?foo=bar&foo=bar2
> Should be converted to:
> foo = ["bar", "bar2"]
> Instead, the last element overwrites it. So in the above example, excluding the 2nd variety, you would get:
> foo = "bar2"
> I can't find a W3C document to back up this behaviour - but certainly in PHP and Java, this is normal behaviour. jQuery also converts an array into this format too, so if it's not "standard" it's certainly expected.
> According to "rnewson" who I was chatting to on IRC - the reason this is happening is that the URL query is being converted to a JSON object. Therefore, two items with the same key name would overwrite each other. He also says the following:
> "yes, I think you'd want to convert "foo=bar&foo=baz" into "foo":["bar","baz"] instead of [{"foo","bar"},{"foo","baz"}] in couch_httpd_external's to_json_terms function."
> I have put a work around in my own code, so this isn't a priority for me - but perhaps if someone else already has the relevant bit of code open... :)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira