summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-05-21 12:26:03 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-05-22 11:48:13 -0400
commitd3368a8daf4ab791a8ef3b34c44df6d3270dab37 (patch)
treebf891c2e3fe80d32c6b457571e00a2274ab79a1c
parentcce72e2d36c5efe53bb026a0d98f835d16440ffa (diff)
downloadqtlocation-mapboxgl-d3368a8daf4ab791a8ef3b34c44df6d3270dab37.tar.gz
[ios, macos] Fix keypath expressions, a json object is parsed incorrectly for nested keypaths.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm3
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm12
2 files changed, 14 insertions, 1 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index af4a197662..653e3d67e6 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1070,7 +1070,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
case NSKeyPathExpressionType: {
NSArray *expressionObject;
- for (NSString *pathComponent in self.keyPath.pathComponents.reverseObjectEnumerator) {
+ NSArray *keyPath = [self.keyPath componentsSeparatedByString:@"."];
+ for (NSString *pathComponent in keyPath) {
if (expressionObject) {
expressionObject = @[@"get", pathComponent, expressionObject];
} else {
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index dbdad2ed13..8870618cef 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -306,6 +306,18 @@ using namespace std::string_literals;
XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
+ {
+ NSExpression *expression = [NSExpression expressionForKeyPath:@"lineStyle.color"];
+ NSArray *jsonExpression = @[@"get", @"color", @[@"get", @"lineStyle"]];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
+ {
+ NSExpression *expression = [NSExpression expressionForKeyPath:@"map.box.gl"];
+ NSArray *jsonExpression = @[@"get", @"gl", @[@"get", @"box", @[@"get", @"map"]]];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
}
- (void)testStatisticalExpressionObject {