diff --git a/IBMCloudAppIDTests/UtilsTests.swift b/IBMCloudAppIDTests/UtilsTests.swift index e175b16..76cdedd 100644 --- a/IBMCloudAppIDTests/UtilsTests.swift +++ b/IBMCloudAppIDTests/UtilsTests.swift @@ -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 = "test+test@test.com" + 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=" diff --git a/Source/IBMCloudAppID/internal/RegistrationManager.swift b/Source/IBMCloudAppID/internal/RegistrationManager.swift index 1122859..7b0b860 100644 --- a/Source/IBMCloudAppID/internal/RegistrationManager.swift +++ b/Source/IBMCloudAppID/internal/RegistrationManager.swift @@ -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) } diff --git a/Source/IBMCloudAppID/internal/Utils.swift b/Source/IBMCloudAppID/internal/Utils.swift index daccde2..563805b 100644 --- a/Source/IBMCloudAppID/internal/Utils.swift +++ b/Source/IBMCloudAppID/internal/Utils.swift @@ -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)!)) } }