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

Url encoding #188

Open
wants to merge 7 commits into
base: development
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: objective-c
matrix:
include:
- osx_image: xcode10.2
- osx_image: xcode11.4
install:
- gem install jazzy
- gem install slather -v 2.4.5
- gem install slather -v 2.4.7
before_script:
- rm -rf ~/Library/Developer/Xcode/DerivedData
script:
Expand Down
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 Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use_frameworks!
def shared_pods
platform :ios, '10.0'
pod 'BMSCore', '~> 2.4.0'
pod 'JOSESwift', '~> 1.8.0'
pod 'JOSESwift', '~> 2.1.0'
end

target 'IBMCloudAppID' do
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