File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -101,9 +101,20 @@ -(void)attachBodyToRequest:(NSMutableURLRequest *)request withParameters:(NSDict
101101 }
102102
103103 NSError *error;
104- NSData *jsonData = [NSJSONSerialization dataWithJSONObject: parameters options: NSJSONWritingPrettyPrinted error: &error];
105-
106- request.HTTPBody = jsonData;
104+ NSData *requestData = [NSJSONSerialization dataWithJSONObject: parameters options: 0 error: &error];
105+ NSString *requestString = [[NSString alloc ] initWithData: requestData encoding: NSUTF8StringEncoding];
106+
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+
110+ if ([matches count ] > 0 ) {
111+ NSTextCheckingResult *match = matches[0 ];
112+ NSString *matched = [requestString substringWithRange: [match range ]];
113+ NSString *unescapedEID = [matched stringByReplacingOccurrencesOfString: @" \\ /" withString: @" /" ];
114+ requestString = [requestString stringByReplacingOccurrencesOfString: matched withString: unescapedEID];
115+ }
116+
117+ request.HTTPBody = [requestString dataUsingEncoding: NSUTF8StringEncoding];
107118}
108119
109120-(void )attachQueryParametersToRequest : (NSMutableURLRequest *)request withParameters : (NSDictionary *)parameters {
Original file line number Diff line number Diff line change @@ -724,6 +724,15 @@ - (void)testSendExternalUserId {
724724 XCTAssertTrue (checkHttpBody (request.urlRequest .HTTPBody , @{@" app_id" : testAppId, @" external_user_id" : testExternalUserId}));
725725}
726726
727+ - (void )testSendExternalUserIdWithForwardSlashes {
728+ let externalUserId = @" abc/123" ;
729+ let request = [OSRequestUpdateExternalUserId withUserId: externalUserId withUserIdHashToken: nil withOneSignalUserId: testUserId appId: testAppId];
730+ let correctUrl = correctUrlWithPath ([NSString stringWithFormat: @" players/%@ " , testUserId]);
731+
732+ XCTAssertTrue ([correctUrl isEqualToString: request.urlRequest.URL.absoluteString]);
733+ XCTAssertTrue (checkHttpBody (request.urlRequest .HTTPBody , @{@" app_id" : testAppId, @" external_user_id" : externalUserId}));
734+ }
735+
727736- (void )testSendExternalWithAuthUserId {
728737 let request = [OSRequestUpdateExternalUserId withUserId: testExternalUserId withUserIdHashToken: testExternalUserIdHashToken withOneSignalUserId: testUserId appId: testAppId];
729738
You can’t perform that action at this time.
0 commit comments