diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2018-07-05 16:50:36 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2018-07-09 16:03:03 -0700 |
commit | ec8ac3c64fd4a89b0744da970eb221af3567707c (patch) | |
tree | f1b7bd74cbbd9dbf847c0ba6355dce4116fc3b86 | |
parent | f11ab91fc448aca1155b42a53aaa77cfce62f412 (diff) | |
download | qtlocation-mapboxgl-ec8ac3c64fd4a89b0744da970eb221af3567707c.tar.gz |
[ios, macos] Allow unwrapped arguments in match expressions
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 14 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 7 | ||||
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/macos/CHANGELOG.md | 1 |
4 files changed, 18 insertions, 5 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index d03d7dbaec..5cb69d11dc 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1367,11 +1367,15 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { for (NSUInteger index = minimumIndex; index < arguments.count; index++) { NSArray *argumentObject = arguments[index].mgl_jsonExpressionObject; // match operators with arrays as matching values should not parse arrays using the literal operator. - if (index > 0 && index < arguments.count - 1 && !(index % 2 == 0) - && (arguments[index].expressionType == NSAggregateExpressionType || - (arguments[index].expressionType == NSConstantValueExpressionType && [arguments[index].constantValue isKindOfClass:[NSArray class]]))) { - - argumentObject = argumentObject.count == 2 ? argumentObject[1] : argumentObject; + if (index > 0 && index < arguments.count - 1 && !(index % 2 == 0)) { + NSExpression *expression = arguments[index]; + if (![expression isKindOfClass:[NSExpression class]]) { + expression = [NSExpression expressionForConstantValue:expression]; + } + if (expression.expressionType == NSAggregateExpressionType || + (expression.expressionType == NSConstantValueExpressionType && [expression.constantValue isKindOfClass:[NSArray class]])) { + argumentObject = argumentObject.count == 2 ? argumentObject[1] : argumentObject; + } } [expressionObject addObject:argumentObject]; } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 8870618cef..01a279950b 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -795,6 +795,13 @@ using namespace std::string_literals; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_MATCH(x, %@, 'Apple', %@, 'Banana', 'Kumquat')", + @[@"a", @"A"], @"Bb"]; + NSArray *jsonExpression = @[@"match", @[@"get", @"x"], @[@"a", @"A"], @"Apple", @"Bb", @"Banana", @"Kumquat"]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression].description, expression.description); + } } - (void)testCoalesceExpressionObject { diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 115a608918..95e92d0165 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -15,6 +15,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * The `c` and `d` options are supported within comparison predicates for case and diacritic insensitivity, respectively. ([#12329](https://github.com/mapbox/mapbox-gl-native/pull/12329)) * Added the `collator` and `resolved-locale` expression operators to more precisely compare strings in style JSON. A subset of this functionality is available through predicate options when creating an `NSPredicate`. ([#11869](https://github.com/mapbox/mapbox-gl-native/pull/11869)) * Fixed a crash when trying to parse expressions containing legacy filters. ([#12263](https://github.com/mapbox/mapbox-gl-native/pull/12263)) +* Fixed a crash that occurred when creating an `MGL_MATCH` expression using non-expressions as arguments. ([#12332](https://github.com/mapbox/mapbox-gl-native/pull/12332)) ### Networking and storage diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 1d5eab97fb..5e704c694a 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -9,6 +9,7 @@ * The `c` and `d` options are supported within comparison predicates for case and diacritic insensitivity, respectively. ([#12329](https://github.com/mapbox/mapbox-gl-native/pull/12329)) * Added the `collator` and `resolved-locale` expression operators to more precisely compare strings in style JSON. A subset of this functionality is available through predicate options when creating an `NSPredicate`. ([#11869](https://github.com/mapbox/mapbox-gl-native/pull/11869)) * Fixed a crash in `-[MGLStyle localizeLabelsIntoLocale:]` on macOS 10.11. ([#12123](https://github.com/mapbox/mapbox-gl-native/pull/12123)) +* Fixed a crash that occurred when creating an `MGL_MATCH` expression using non-expressions as arguments. ([#12332](https://github.com/mapbox/mapbox-gl-native/pull/12332)) * Fixed a crash when trying to parse expressions containing legacy filters. ([#12263](https://github.com/mapbox/mapbox-gl-native/pull/12263)) ## Other changes |