[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.
This commit is contained in:
Fabian Guerra Soto
2019-03-07 19:28:20 -08:00
committed by GitHub
parent d0ffaa4245
commit 79f3307c4b
4 changed files with 32 additions and 1 deletions

View File

@@ -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:"]) {

View File

@@ -1001,6 +1001,23 @@ using namespace std::string_literals;
NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('random', 1, 2, 3, 4)"];
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),

View File

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

View File

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