Skip to content

Commit

Permalink
SDK-2533 Integration validator crash fix
Browse files Browse the repository at this point in the history
* Fixed function compareUriSchemes to handle empty strings
* Added wrapper function for compareUriSchemes to make it testable.
* Added unit test
  • Loading branch information
NidhiDixit09 committed Jan 6, 2025
1 parent 13d38e4 commit 3254bfc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
35 changes: 35 additions & 0 deletions Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#import <XCTest/XCTest.h>
#import "BNCSystemObserver.h"

@interface BNCSystemObserver ()
+ (BOOL)compareUriSchemes:(NSString *)serverUriScheme With:(NSArray *)urlTypes;
@end

@interface BNCSystemObserverTests : XCTestCase

@end
Expand Down Expand Up @@ -100,4 +104,35 @@ - (void)testIsAppClip {
XCTAssert(![BNCSystemObserver isAppClip]);
}

- (void)testCompareURIScemes {

NSString *serverUriScheme = @"bnctest://";
NSArray *urlTypes = @[@{@"CFBundleURLSchemes" : @[@""]}, @{@"CFBundleURLSchemes" : @[@"bnctest", @"xyzs"]}];

XCTAssertTrue([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]);

XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:nil]);

XCTAssertFalse([BNCSystemObserver compareUriSchemes:nil With:nil]);

XCTAssertFalse([BNCSystemObserver compareUriSchemes:nil With:urlTypes]);

serverUriScheme = @":/";
XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]);

serverUriScheme = @"bnctest";
XCTAssertTrue([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]);

serverUriScheme = @"bnctest://";
urlTypes = @[ @{@"CFBundleURLSchemes" : @[@"bnctestX", @"xyzs"]}];
XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]);

serverUriScheme = @"://";
XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]);

XCTAssertFalse([BNCSystemObserver compareUriSchemes:@"" With:urlTypes]);

XCTAssertFalse([BNCSystemObserver compareUriSchemes:@"" With:@[@{}]]);
}

@end
15 changes: 13 additions & 2 deletions Sources/BranchSDK/BNCSystemObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,25 @@ + (NSString *)defaultURIScheme {

+ (BOOL)compareUriSchemes : (NSString *) serverUriScheme {
NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
return [self compareUriSchemes:serverUriScheme With:urlTypes];
}

+ (BOOL)compareUriSchemes:(NSString *)serverUriScheme With:(NSArray *)urlTypes {
NSString * serverUriSchemeWithoutSuffix ;

if ([serverUriScheme hasSuffix:@"://"]) {
serverUriSchemeWithoutSuffix = [serverUriScheme substringToIndex:[serverUriScheme length] - 3];
} else {
serverUriSchemeWithoutSuffix = serverUriScheme;
}

for (NSDictionary *urlType in urlTypes) {

NSArray *urlSchemes = [urlType objectForKey:@"CFBundleURLSchemes"];
for (NSString *uriScheme in urlSchemes) {
NSString * serverUriSchemeWithoutSuffix = [serverUriScheme substringToIndex:[serverUriScheme length] - 3];
if ([uriScheme isEqualToString:serverUriSchemeWithoutSuffix]) {
return true; }
return true;
}
}
}
return false;
Expand Down

0 comments on commit 3254bfc

Please sign in to comment.