Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Allow unwrapped arguments in match expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jul 9, 2018
1 parent f11ab91 commit ec8ac3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,15 @@ - (id)mgl_jsonMatchExpressionObject {
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];
}
Expand Down
7 changes: 7 additions & 0 deletions platform/darwin/test/MGLExpressionTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,13 @@ - (void)testMatchExpressionObject {
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 {
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec8ac3c

Please sign in to comment.