From bed4b5c8377d0eef4af741c0a2293dccb2eef707 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 16 Feb 2024 21:20:21 +0530 Subject: [PATCH] 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