iOS: Fix case image expression crash (#4269)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Sargun Vohra
2026-04-28 06:08:11 -07:00
committed by GitHub
parent 67a29aabb0
commit 086bfcae4c
2 changed files with 19 additions and 2 deletions

View File

@@ -1559,7 +1559,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) {
firstCondition = self.operand;
}
if ([firstCondition respondsToSelector:@selector(constantValue)] &&
if (firstCondition.expressionType == NSConstantValueExpressionType &&
[firstCondition.constantValue isKindOfClass:[NSComparisonPredicate class]]) {
NSPredicate *predicate = (NSPredicate *)firstCondition.constantValue;
condition = predicate.mgl_jsonExpressionObject;
@@ -1572,7 +1572,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) {
isAftermarketFunction ? self.arguments : self.arguments[minimumIndex].constantValue;
for (NSUInteger index = minimumIndex; index < arguments.count; index++) {
if ([arguments[index] respondsToSelector:@selector(constantValue)] &&
if (arguments[index].expressionType == NSConstantValueExpressionType &&
[arguments[index].constantValue isKindOfClass:[NSComparisonPredicate class]]) {
NSPredicate *predicate = (NSPredicate *)arguments[index].constantValue;
[expressionObject addObject:predicate.mgl_jsonExpressionObject];

View File

@@ -318,6 +318,23 @@
NSException, @"MLNRedundantLayerIdentifierException");
}
- (void)testSymbolLayerIconImageNameWithMultiCaseImageExpression {
MLNPointFeature *feature = [[MLNPointFeature alloc] init];
MLNShapeSource *source = [[MLNShapeSource alloc] initWithIdentifier:@"sourceID"
shape:feature
options:nil];
MLNSymbolStyleLayer *layer = [[MLNSymbolStyleLayer alloc] initWithIdentifier:@"layerID"
source:source];
// Reproduces https://github.com/maplibre/maplibre-native/issues/3477.
NSArray *jsonExpression = @[
@"case", @[ @"==", @[ @"get", @"icon" ], @"1" ], @[ @"image", @"icon1" ],
@[ @"==", @[ @"get", @"icon" ], @"2" ], @[ @"image", @"icon2" ], @[ @"image", @"icon3" ]
];
NSExpression *expression = [NSExpression expressionWithMLNJSONObject:jsonExpression];
XCTAssertNoThrow(layer.iconImageName = expression);
}
- (void)testRemovingLayerBeforeAddingSameLayer {
{
MLNShapeSource *source =