Skip to content

Commit

Permalink
The original code used boolValue
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-branch committed Feb 26, 2024
1 parent 9eb07e2 commit 1b03a81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Branch-TestBed/Branch-SDK-Tests/NSMutableDictionaryBranchTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,27 @@ - (void)testGetBooleanForKey {
@"bool2" : @(0),
@"bool3" : @"1", // valid bool
@"bool4" : @"0", // valid bool
@"bool5" : @"YES", // invalid bool, server expects a number. treated as false
@"bool6" : @"NO", // invalid bool, server expects a number. treated as false
@"bool5" : @"YES",
@"bool6" : @"NO",
@"bool7" : @(-1), // all non-zero numbers are true
@"bool8" : @(1234), // all non-zero numbers are true
@"bool9" : @[ ] // invalid bool, treated as false

@"bool9" : @[ ], // invalid bool, treated as false
@"bool10": @"true",
@"bool11": @"false"
};
NSMutableDictionary *dict = [tmp mutableCopy];

XCTAssertTrue([dict bnc_getBooleanForKey:@"bool1"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool2"]);
XCTAssertTrue([dict bnc_getBooleanForKey:@"bool3"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool4"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool5"]);
XCTAssertTrue([dict bnc_getBooleanForKey:@"bool5"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool6"]);
XCTAssertTrue([dict bnc_getBooleanForKey:@"bool7"]);
XCTAssertTrue([dict bnc_getBooleanForKey:@"bool8"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool9"]);
XCTAssertTrue([dict bnc_getBooleanForKey:@"bool10"]);
XCTAssertFalse([dict bnc_getBooleanForKey:@"bool11"]);
}

@end
2 changes: 1 addition & 1 deletion Sources/BranchSDK/NSMutableDictionary+Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (BOOL)bnc_getBooleanForKey:(NSString *)key {
returnValue = [number boolValue];
} else if ([tmp isKindOfClass:[NSString class]]) {
NSString *numberAsString = (NSString *)tmp;
returnValue = [numberAsString doubleValue];
returnValue = [numberAsString boolValue];
}

return returnValue;
Expand Down

0 comments on commit 1b03a81

Please sign in to comment.