[ios, macos] Allow unwrapped arguments in match expressions

This commit is contained in:
Minh Nguyễn
2018-07-05 16:50:36 -07:00
committed by Minh Nguyễn
parent f11ab91fc4
commit ec8ac3c64f
4 changed files with 18 additions and 5 deletions

View File

@@ -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];
}

View File

@@ -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 {

View File

@@ -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

View File

@@ -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