From 2c62f0a15bed02bc6ca014fd113d5e62d9808624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 17 Dec 2016 15:39:43 -0800 Subject: [PATCH] [ios, macos] Fixed null expression crash Convert NSNull into an mbgl null value. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 5 +++-- platform/darwin/test/MGLExpressionTests.mm | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 392a6d7f5..6af069487 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -55,9 +55,10 @@ // We use long long here to avoid any truncation. return { (int64_t)number.longLongValue }; } + } else if (value != [NSNull null]) { + [NSException raise:@"Value not handled" + format:@"Can’t convert %s:%@ to mbgl::Value", [value objCType], value]; } - [NSException raise:@"Value not handled" - format:@"Can’t convert %s:%@ to mbgl::Value", [value objCType], value]; return { }; } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 971f7d0e5..e78f87a99 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -197,4 +197,13 @@ } } +#pragma mark - Null Tests + +- (void)testExpressionConversionNull +{ + NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNull null]]; + mbgl::Value convertedValue = predicate.rightExpression.mgl_filterValue; + XCTAssertTrue(convertedValue.is()); +} + @end