Added extraEncodedParameters

This commit is contained in:
Krishna Kishore Bandaru 2024-02-16 21:20:21 +05:30
parent e741805f35
commit bed4b5c837
3 changed files with 8 additions and 17 deletions

View File

@ -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;

View File

@ -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";

View File

@ -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