summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-20 10:49:23 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-03-20 10:54:55 -0700
commit2566bc3d06944641353f92e3ca2fd5699ee12378 (patch)
tree897806cb2e31acb0f261925977ba1954afd861b4
parent174c8fa7e4927ebf28a3d0e07c995d3e3d69de76 (diff)
downloadqtlocation-mapboxgl-upstream/fabian-cp-format-exp-fix.tar.gz
[ios, macos] Fix format expression parsing. (#14168)upstream/fabian-cp-format-exp-fix
Fixed a parsing issue when a non-constant expression was passed to MGLAttributedExpression.expression property.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm18
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm20
2 files changed, 25 insertions, 13 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index f0f1d62ef7..091f1edf9d 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1016,14 +1016,10 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
if ([constantValue isKindOfClass:[MGLAttributedExpression class]]) {
MGLAttributedExpression *attributedExpression = (MGLAttributedExpression *)constantValue;
id jsonObject = attributedExpression.expression.mgl_jsonExpressionObject;
- NSMutableArray *attributes = [NSMutableArray array];
- if ([jsonObject isKindOfClass:[NSArray class]]) {
- [attributes addObjectsFromArray:jsonObject];
- } else {
- [attributes addObject:jsonObject];
- }
+ NSMutableDictionary *attributedDictionary = [NSMutableDictionary dictionary];
+
if (attributedExpression.attributes) {
- NSMutableDictionary *attributedDictionary = [NSMutableDictionary dictionaryWithDictionary:attributedExpression.attributes];
+ attributedDictionary = [NSMutableDictionary dictionaryWithDictionary:attributedExpression.attributes];
if (attributedDictionary[MGLFontNamesAttribute]) {
attributedDictionary[MGLFontNamesAttribute] = @[@"literal", attributedDictionary[MGLFontNamesAttribute]];
}
@@ -1031,12 +1027,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
MGLColor *color = attributedDictionary[MGLFontColorAttribute];
attributedDictionary[MGLFontColorAttribute] = color.mgl_jsonExpressionObject;
}
- [attributes addObject:attributedDictionary];
- } else {
- [attributes addObject:@{}];
- }
-
- return attributes;
+ }
+ return @[jsonObject, attributedDictionary];
}
return self.constantValue;
}
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index 8e99ed596e..ec51f2bf6c 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1063,6 +1063,14 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
{
+ MGLAttributedExpression *attribute1 = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionForConstantValue:@"foo"]] ;
+ NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@)", MGLConstantExpression(attribute1)];
+
+ NSArray *jsonExpression = @[ @"format", @"foo", @{ } ];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
+ {
MGLAttributedExpression *attribute1 = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionForConstantValue:@"foo"]
attributes:@{ MGLFontSizeAttribute: @(1.2),
MGLFontColorAttribute: @"yellow",
@@ -1087,6 +1095,18 @@ using namespace std::string_literals;
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
{
+ MGLAttributedExpression *attribute1 = [[MGLAttributedExpression alloc] initWithExpression:[NSExpression expressionWithFormat:@"CAST(x, 'NSString')"]
+ attributes:@{ MGLFontSizeAttribute: @(1.2),
+ MGLFontColorAttribute: [MGLColor redColor],
+ MGLFontNamesAttribute: @[ @"DIN Offc Pro Bold", @"Arial Unicode MS Bold" ]
+ }] ;
+ NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_attributed:(%@)", MGLConstantExpression(attribute1)];
+
+ NSArray *jsonExpression = @[ @"format", @[@"to-string", @[@"get", @"x"]], @{ @"font-scale": @1.2, @"text-color": @[@"rgb", @255, @0, @0] , @"text-font" : @[ @"literal", @[ @"DIN Offc Pro Bold", @"Arial Unicode MS Bold" ]]} ];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
+ {
MGLAttributedExpression *attribute1 = [MGLAttributedExpression attributedExpression:[NSExpression expressionForConstantValue:@"foo"]
fontNames:nil
fontSize:@(1.2)];