Skip to content

Commit 48c144c

Browse files
committed
Fix intermittent crash in sanitizedStringFromString and a potential solution
1 parent 50d4c20 commit 48c144c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
8383

8484
- (void)addInstrumentationDictionaryKey:(NSString *)key value:(NSString *)value;
8585
- (NSMutableDictionary *)instrumentationDictionary;
86+
- (NSDictionary *)instrumentationParameters; // a safe copy to use in a POST body
8687
- (void)clearInstrumentationDictionary;
8788

8889
- (void)saveBranchAnalyticsData:(NSDictionary *)analyticsData;

Branch-SDK/BNCPreferenceHelper.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
492492
}
493493
}
494494

495+
- (NSDictionary *)instrumentationParameters {
496+
@synchronized (self) {
497+
if (_instrumentationDictionary.count == 0) {
498+
return nil; // this avoids the .count check in prepareParamDict
499+
}
500+
return [[NSDictionary alloc] initWithDictionary:_instrumentationDictionary];
501+
}
502+
}
503+
495504
- (NSMutableDictionary *)instrumentationDictionary {
496505
@synchronized (self) {
497506
if (!_instrumentationDictionary) {

Branch-SDK/BNCServerInterface.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,12 @@ - (NSMutableDictionary *)prepareParamDict:(NSDictionary *)params
453453
fullParamDict[BRANCH_REQUEST_KEY_STATE] = metadata;
454454
}
455455
// we only send instrumentation info in the POST body request
456-
if (self.preferenceHelper.instrumentationDictionary.count && [reqType isEqualToString:@"POST"]) {
457-
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = self.preferenceHelper.instrumentationDictionary;
456+
if ([reqType isEqualToString:@"POST"]) {
457+
NSDictionary *instrumentationDictionary = self.preferenceHelper.instrumentationParameters;
458+
if (instrumentationDictionary) {
459+
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = instrumentationDictionary;
460+
}
458461
}
459-
460462
return fullParamDict;
461463
}
462464

0 commit comments

Comments
 (0)