From cd2090f9be30aba6e75a50377fc4eecd36c1e993 Mon Sep 17 00:00:00 2001 From: r-aamir <8693597+r-aamir@users.noreply.github.com> Date: Wed, 12 Dec 2018 23:28:57 +0300 Subject: [PATCH] Bug fix when nested array in GET query parameters 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 ) ) --- Source/Request.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Request.swift b/Source/Request.swift index 6767352..a0490b7 100644 --- a/Source/Request.swift +++ b/Source/Request.swift @@ -135,8 +135,8 @@ extension Array: HTTPParameterProtocol { public func createPairs(_ key: String?) -> [HTTPPair] { var collect = [HTTPPair]() - for v in self { - let useKey = key != nil ? "\(key!)[]" : key + for (i, v) in self.enumerated() { + let useKey = key != nil ? "\(key!)[\(i)]" : key if let subParam = v as? HTTPParameterProtocol { collect.append(contentsOf: subParam.createPairs(useKey)) } else {