Skip to content

Conversation

r-aamir
Copy link
Contributor

@r-aamir r-aamir commented Dec 12, 2018

Its better to have array indexes in query parameter names, such as:
swifthttp.com?array[0]=value1&array[1]=value2

It fixes an issue when a GET request contains nested arrays, like the one below:

let dict: [String : Any] = [
    "boundingbox": [["coord1", "coord2"]]
]

Currently Array.createPairs produces names without indexes:
swifthttp.com?boundingbox[][]=coord1&boundingbox[][]=coord2
Which causes boundingbox query parameter 2 root elements, as seen below

Array (
    [0] => Array (     // 1st Element
        [0] => coord1
    )
    [1] => Array (     // 2nd Element
        [0] => coord2
    )
)

With this change we will have following URL:
swifthttp.com?boundingbox[0][0]=coord1&boundingbox[0][1]=coord2

Now server reads the array properly as 1 root element, as seen below

Array (
    [0] => Array (
        [0] => coord1
        [1] => coord2
    )
)

This pull request is to have indexes in query parameter names where values are array, it fixes following issue:

When a GET request contains such an array

```
let dict: [String : Any] = [
    "boundingbox": [["coord1", "coord2"]]
]
```
Here is an error in URL:
swifthttp.com?boundingbox[][]=coord1&boundingbox[][]=coord2
Instead of 1 root element, server reads this parameter as 2 root elements, as seen below

Array (
    [0] => Array (
        [0] => coord1
    )
    [1] => Array (
        [0] => coord2
    )
)

By adding indexes in query parameters here is the fixed URL that is produced:
swifthttp.com?boundingbox[0][0]=coord1&boundingbox[0][1]=coord2

Now server reads the 2 coordinates properly in 1 root element, as seen below
Array (
    [0] => Array (
        [0] => coord1
        [1] => coord2
    )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant