Skip to content

Commit

Permalink
[Issue #34] Fix for array urlencoding (XCode 15.0.1, iOS 17.0) (#35)
Browse files Browse the repository at this point in the history
* Tests fixed

* URLEncode - remove semicolon from allowed characters

* Internal bata version

* Separator extracted as static variable

* Version file restored

---------

Co-authored-by: Marek Matulski <mmatulski-c@hippo.com>
  • Loading branch information
mmatulski and Marek Matulski authored Jan 16, 2024
1 parent 37d7b67 commit 1b08082
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Sources/SmartyStreets/SmartyRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public class SmartyRequest {
}

func urlEncode(value: String) -> String {
return value.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
var allowedCharacters = CharacterSet.urlPathAllowed
allowedCharacters.remove(charactersIn: USAutocompleteProClient.arrayItemsSeparator)
return value.addingPercentEncoding(withAllowedCharacters: allowedCharacters)!
}

func setPayload(payload:Data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Foundation

public class USAutocompleteProClient: NSObject {
// It is recommended to instantiate this class using SSClientBuilder


static let arrayItemsSeparator = ";"

var sender:SmartySender
public var serializer:SmartySerializer

Expand Down Expand Up @@ -65,6 +67,6 @@ public class USAutocompleteProClient: NSObject {
return String()
}

return list.joined(separator: ";")
return list.joined(separator: Self.arrayItemsSeparator)
}
}
6 changes: 6 additions & 0 deletions Tests/SmartyStreetsTests/SmartyRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ class SmartyRequestTests: XCTestCase {
XCTAssertEqual(url, "https://fakesearch.com/lookup?street=Parks%20Blvd")
}

func testGetURLWithURLEncodedArray() {
smartyRequest.urlPrefix = "https://fakesearch.com/lookup?"
smartyRequest.setValue(value: "abc;def", HTTPParameterField: "array")
let url = smartyRequest.getUrl()
XCTAssertEqual(url, "https://fakesearch.com/lookup?array=abc%3Bdef")
}
}

0 comments on commit 1b08082

Please sign in to comment.