Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix not working url encoding function in Utils #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions IBMCloudAppIDTests/UtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class UtilsTest: XCTestCase {
// XCTAssertEqual(dictionary[AppIDConstants.JSON_APPLICATION_VERSION_KEY] as? String, appIdentity.version)
// XCTAssertEqual(dictionary[AppIDConstants.JSON_ENVIRONMENT_KEY] as? String, AppIDConstants.JSON_IOS_ENVIRONMENT_VALUE)
// }

func testURLEncoding() {
let strToEncode = "[email protected]"
let exceptedStr = "test%2Btest%40test.com"

let resultStr = Utils.urlEncode(strToEncode)
XCTAssertEqual(resultStr, exceptedStr, "Could not url Encoded")
}

func testDecodeBase64WithString() {
let str = "VGhpcyBpcyBhIFV0aWxzIHVuaXRUZXN0IHR+c/Q="
let strSafe = "VGhpcyBpcyBhIFV0aWxzIHVuaXRUZXN0IHR-c_Q="
Expand Down
2 changes: 1 addition & 1 deletion Source/IBMCloudAppID/internal/RegistrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class RegistrationManager {

let request:Request = Request(url: Config.getServerUrl(appId: self.appId) + "/clients",method: HttpMethod.POST, headers: [Request.contentType : "application/json"], queryParameters: nil, timeout: 0)
request.timeout = BMSClient.sharedInstance.requestTimeout
let registrationParamsAsData = try? Utils.urlEncode(Utils.JSONStringify(registrationParams as AnyObject)).data(using: .utf8) ?? Data()
let registrationParamsAsData = try? Utils.JSONStringify(registrationParams as AnyObject).data(using: .utf8) ?? Data()
sendRequest(request: request, registrationParamsAsData: registrationParamsAsData, internalCallBack: internalCallBack)

}
Expand Down
4 changes: 2 additions & 2 deletions Source/IBMCloudAppID/internal/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ public class Utils {
internal static func urlEncode(_ str:String) -> String{
var encodedString = ""
var unchangedCharacters = ""
let FORM_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#&!$(),~%"
let FORM_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#&!$(),~%+".unicodeScalars

for element: Int in 0x20..<0x7f {
if !FORM_ENCODE_SET.contains(String(describing: UnicodeScalar(element))) {
if !FORM_ENCODE_SET.contains(UnicodeScalar(element)!) {
unchangedCharacters += String(Character(UnicodeScalar(element)!))
}
}
Expand Down