summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-07 19:28:20 -0800
committerGitHub <noreply@github.com>2019-03-07 19:28:20 -0800
commit79f3307c4be67ee1f9be1e90e4d5d2031e27ab8e (patch)
tree192396b53664ca8b983453e1ced4ce36582d0904
parentd0ffaa4245802c2081f899eaed80b730558c9227 (diff)
downloadqtlocation-mapboxgl-79f3307c4be67ee1f9be1e90e4d5d2031e27ab8e.tar.gz
[ios, macos] Fix a bug with multiple format expressions. (#14064)
Fixed a bug where `format` expressions using the generic `MGL_FUNCTION` binding ignored multiple formatting parameters.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm14
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm17
-rw-r--r--platform/ios/CHANGELOG.md1
-rw-r--r--platform/macos/CHANGELOG.md1
4 files changed, 32 insertions, 1 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 527cb64b3d..6aaba4dd90 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1126,7 +1126,19 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
if (firstOp.expressionType == NSConstantValueExpressionType
&& [firstOp.constantValue isEqualToString:@"format"]) {
// Avoid wrapping format options object in literal expression.
- return @[@"format", self.arguments[1].mgl_jsonExpressionObject, self.arguments[2].constantValue];
+ NSMutableArray *expressionObject = [NSMutableArray array];
+ [expressionObject addObject:@"format"];
+
+ for (NSUInteger index = 1; index < self.arguments.count; index++) {
+ if (index % 2 == 1) {
+ [expressionObject addObject:self.arguments[index].mgl_jsonExpressionObject];
+ } else {
+ [expressionObject addObject:self.arguments[index].constantValue];
+ }
+
+ }
+
+ return expressionObject;
}
return self.arguments.mgl_jsonExpressionObject;
} else if (op == [MGLColor class] && [function isEqualToString:@"colorWithRed:green:blue:alpha:"]) {
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm
index f869275dd3..bcc30e49fd 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -1002,6 +1002,23 @@ using namespace std::string_literals;
XCTAssertThrowsSpecificNamed([expression expressionValueWithObject:nil context:nil], NSException, NSInvalidArgumentException);
}
{
+ NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('format', 'foo', %@, '\r', %@, 'biz', %@, 'bar', %@)", @{@"font-scale": @1.2}, @{}, @{@"font-scale": @1.0}, @{@"font-scale": @0.8}];
+ NSArray *jsonExpression = @[@"format", @"foo", @{@"font-scale": @1.2}, @"\r", @{}, @"biz", @{@"font-scale": @1.0}, @"bar", @{@"font-scale": @0.8}];
+
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+
+ NSExpression *encodedExpression = [NSExpression expressionWithMGLJSONObject:jsonExpression];
+
+ // Expressions encoded from a json create a different constant abstract type
+ // thus even tho knowing that the constant values are the same, the base
+ // class is not. This compares the resulting array which is type agnostic encoding.
+ for (NSUInteger index = 0; index < jsonExpression.count; index++) {
+ NSExpression *left = encodedExpression.mgl_jsonExpressionObject[index];
+ NSExpression *right = expression.mgl_jsonExpressionObject[index];
+ XCTAssertEqualObjects(left.mgl_jsonExpressionObject, right.mgl_jsonExpressionObject);
+ }
+ }
+ {
NSArray *arguments = @[
MGLConstantExpression(@"one"), MGLConstantExpression(@1),
[NSExpression expressionForVariable:@"one"],
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md
index 3967f53bf6..d27f662c75 100644
--- a/platform/ios/CHANGELOG.md
+++ b/platform/ios/CHANGELOG.md
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Client-side text rendering of CJK ideographs is now enabled by default. ([#13988](https://github.com/mapbox/mapbox-gl-native/pull/13988))
* Added an MGLMapView.prefetchesTiles property that you can disable if you don’t want to prefetch simplified tiles as a performance optimization. ([#14031](https://github.com/mapbox/mapbox-gl-native/pull/14031))
+* Fixed an issue that caused `MGL_FUNCTION` to ignore multiple formatting parameters when passed a `format` function as parameter. ([#14064](https://github.com/mapbox/mapbox-gl-native/pull/14064))
## 4.9.0 - February 27, 2019
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index 7e9c844059..ce573e6133 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -8,6 +8,7 @@
* Fixed a crash when casting large numbers in `NSExpression`. ([#13580](https://github.com/mapbox/mapbox-gl-native/pull/13580))
* Added the `-[MGLShapeSource leavesOfCluster:offset:limit:]`, `-[MGLShapeSource childrenOfCluster:]`, `-[MGLShapeSource zoomLevelForExpandingCluster:]` methods for inspecting a cluster in an `MGLShapeSource`s created with the `MGLShapeSourceOptionClustered` option. Feature querying now returns clusters represented by `MGLPointFeatureCluster` objects (that conform to the `MGLCluster` protocol). ([#12952](https://github.com/mapbox/mapbox-gl-native/pull/12952)
* Added `MGLNetworkConfiguration` class to customize the SDK's `NSURLSessionConfiguration` object. ([#11447](https://github.com/mapbox/mapbox-gl-native/pull/13886))
+* Fixed an issue that caused `MGL_FUNCTION` to ignore multiple formatting parameters when passed a `format` function as parameter. ([#14064](https://github.com/mapbox/mapbox-gl-native/pull/14064))
### Annotations