SwiftHTTP icon indicating copy to clipboard operation
SwiftHTTP copied to clipboard

Bug fix when nested array in GET query parameters

Open r-aamir opened this issue 7 years ago • 0 comments

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
    )
)

r-aamir avatar Dec 12 '18 20:12 r-aamir