From a0b8459a794304e9ba8bbdd67e30cf891e3cf69f Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 14 Feb 2024 12:58:56 +0530 Subject: [PATCH 1/5] removed extra characters from urlQueryAllowed CharacterSet --- MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index 857310b..002e6a7 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -67,7 +67,10 @@ extension JSONDictionary { } valueString = baseValueString } - let queryItem = URLQueryItem(name: key, value: valueString) + var characterSet = CharacterSet.urlQueryAllowed + characterSet.remove("/") + characterSet.remove(":") + let queryItem = URLQueryItem(name: key, value: valueString.addingPercentEncoding(withAllowedCharacters: characterSet) ?? valueString) queryItems.append(queryItem) } return queryItems From 10b569e3a9308e1ce1fee14eee23b13b34d48617 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 14 Feb 2024 13:14:53 +0530 Subject: [PATCH 2/5] Added comments --- MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index 002e6a7..76c8c53 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -67,9 +67,17 @@ extension JSONDictionary { } valueString = baseValueString } + /*If urlQuery value contains '/' , ':' these characters are passed without encoding, due to this we are seeing inconsistent behaviour. + For Eg: value contains a url: https://vzwsso/executeTask + Expected: https%3A%2F%2Fvzwsso%2FexecuteTask + Current: https://vzwsso/executeTask + So removed possible characters from urlQueryAllowed characterSet. + */ var characterSet = CharacterSet.urlQueryAllowed characterSet.remove("/") characterSet.remove(":") + characterSet.remove("?") + characterSet.remove("=") let queryItem = URLQueryItem(name: key, value: valueString.addingPercentEncoding(withAllowedCharacters: characterSet) ?? valueString) queryItems.append(queryItem) } From 0b23bd8e934fb7d19fccabd77cfd8ac71bde4a25 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 14 Feb 2024 16:26:44 +0530 Subject: [PATCH 3/5] Added new character --- MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index 76c8c53..d5843cb 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -78,6 +78,7 @@ extension JSONDictionary { characterSet.remove(":") characterSet.remove("?") characterSet.remove("=") + characterSet.remove("&") let queryItem = URLQueryItem(name: key, value: valueString.addingPercentEncoding(withAllowedCharacters: characterSet) ?? valueString) queryItems.append(queryItem) } From bed4b5c8377d0eef4af741c0a2293dccb2eef707 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 16 Feb 2024 21:20:21 +0530 Subject: [PATCH 4/5] Added extraEncodedParameters --- .../MVMCore/Constants/MVMCoreJSONConstants.h | 1 + .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 + MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 23 +++++-------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 3a47d8b..f4dccbd 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -58,6 +58,7 @@ extern NSString * const KeyCallNumber; extern NSString * const KeyPhoneNumber; extern NSString * const KeyPresentationStyle; extern NSString * const KeyExtraParameters; +extern NSString * const KeyExtraEncodedParameters; extern NSString * const KeyContextRoot; extern NSString * const KeyType; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 3ad5e93..684b8ca 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -58,6 +58,7 @@ NSString * const KeyCallNumber = @"callNumber"; NSString * const KeyPhoneNumber = @"phoneNumber"; NSString * const KeyPresentationStyle = @"presentationStyle"; NSString * const KeyExtraParameters = @"extraParameters"; +NSString * const KeyExtraEncodedParameters = @"extraEncodedParameters"; NSString * const KeyContextRoot = @"appContext"; NSString * const KeyType = @"type"; diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index d5843cb..819eee4 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -53,7 +53,7 @@ extension JSONDictionary { return string } - public func toUrlQueryItems() throws -> [URLQueryItem] { + public func toUrlQueryItems(shouldRemoveEncoding: Bool = true) throws -> [URLQueryItem] { var queryItems: [URLQueryItem] = [] for (key, value) in self { var valueString: String @@ -62,24 +62,13 @@ extension JSONDictionary { } else if let value = value as? JSONArray { valueString = try value.toJSONString() } else { - guard let baseValueString = String(describing: value.base).removingPercentEncoding else { - throw JSONError.error(message: "query item failed: \(key) value \(value.base)") + valueString = String(describing: value.base) + if shouldRemoveEncoding { + guard let encodedValue = valueString.removingPercentEncoding else { throw JSONError.error(message:"query item failed: \(key) value \(value.base)") } + valueString = encodedValue } - valueString = baseValueString } - /*If urlQuery value contains '/' , ':' these characters are passed without encoding, due to this we are seeing inconsistent behaviour. - For Eg: value contains a url: https://vzwsso/executeTask - Expected: https%3A%2F%2Fvzwsso%2FexecuteTask - Current: https://vzwsso/executeTask - So removed possible characters from urlQueryAllowed characterSet. - */ - var characterSet = CharacterSet.urlQueryAllowed - characterSet.remove("/") - characterSet.remove(":") - characterSet.remove("?") - characterSet.remove("=") - characterSet.remove("&") - let queryItem = URLQueryItem(name: key, value: valueString.addingPercentEncoding(withAllowedCharacters: characterSet) ?? valueString) + let queryItem = URLQueryItem(name: key, value: valueString) queryItems.append(queryItem) } return queryItems From d46093887cfee6a4a328b1e9f466fb0c64b5d896 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 5 Mar 2024 11:31:31 +0530 Subject: [PATCH 5/5] updated to shouldRemoveDefaultEncoding --- MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h | 1 - MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m | 1 - MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index f4dccbd..3a47d8b 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -58,7 +58,6 @@ extern NSString * const KeyCallNumber; extern NSString * const KeyPhoneNumber; extern NSString * const KeyPresentationStyle; extern NSString * const KeyExtraParameters; -extern NSString * const KeyExtraEncodedParameters; extern NSString * const KeyContextRoot; extern NSString * const KeyType; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 684b8ca..3ad5e93 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -58,7 +58,6 @@ NSString * const KeyCallNumber = @"callNumber"; NSString * const KeyPhoneNumber = @"phoneNumber"; NSString * const KeyPresentationStyle = @"presentationStyle"; NSString * const KeyExtraParameters = @"extraParameters"; -NSString * const KeyExtraEncodedParameters = @"extraEncodedParameters"; NSString * const KeyContextRoot = @"appContext"; NSString * const KeyType = @"type"; diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index 819eee4..6b4deef 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -53,7 +53,7 @@ extension JSONDictionary { return string } - public func toUrlQueryItems(shouldRemoveEncoding: Bool = true) throws -> [URLQueryItem] { + public func toUrlQueryItems(shouldRemoveDefaultEncoding: Bool = false) throws -> [URLQueryItem] { var queryItems: [URLQueryItem] = [] for (key, value) in self { var valueString: String @@ -63,7 +63,7 @@ extension JSONDictionary { valueString = try value.toJSONString() } else { valueString = String(describing: value.base) - if shouldRemoveEncoding { + if shouldRemoveDefaultEncoding { guard let encodedValue = valueString.removingPercentEncoding else { throw JSONError.error(message:"query item failed: \(key) value \(value.base)") } valueString = encodedValue }