Skip to content

Commit e885e3e

Browse files
author
Adam Schlesinger
committed
Explicitly mimic Android behavior for unescaping forward slashes in EID
1 parent 66bff0c commit e885e3e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalRequest.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ -(void)attachBodyToRequest:(NSMutableURLRequest *)request withParameters:(NSDict
101101
}
102102

103103
NSError *error;
104-
if (@available(iOS 13, *))
105-
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingWithoutEscapingSlashes error:&error];
106-
else {
107-
NSData* requestData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];
108-
NSString* requestString = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];
109-
requestString = [requestString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
110-
requestData = [requestString dataUsingEncoding:NSUTF8StringEncoding];
104+
NSData *requestData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];
105+
NSString *requestString = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];
111106

112-
request.HTTPBody = requestData;
107+
NSRegularExpression *eidRegex = [NSRegularExpression regularExpressionWithPattern:@"(?<=\"external_user_id\":\").*\\/.*?(?=\",|\"\\})" options:0 error:&error];
108+
NSArray *matches = [eidRegex matchesInString:requestString options:0 range:NSMakeRange(0, [requestString length])];
109+
for (NSTextCheckingResult *match in matches) {
110+
NSString *matched = [requestString substringWithRange:[match range]];
111+
NSString *unescapedEID = [matched stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
112+
requestString = [requestString stringByReplacingOccurrencesOfString:matched withString:unescapedEID];
113113
}
114+
115+
request.HTTPBody = [requestString dataUsingEncoding:NSUTF8StringEncoding];
114116
}
115117

116118
-(void)attachQueryParametersToRequest:(NSMutableURLRequest *)request withParameters:(NSDictionary *)parameters {

0 commit comments

Comments
 (0)