Skip to content

Commit

Permalink
Don’t force cast to NSComparisonPredicate in TERNARY operator (#4232)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored Aug 6, 2024
1 parent 817009f commit de3c570
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- Long-lasting TTID/TTFD spans (#4225). Avoid long TTID spans when the FrameTracker isn't running, which is the case when the app is in the background.
- Missing mach info for crash reports (#4230)
- Crash reports not generated on visionOS (#4229)

- Don’t force cast to `NSComparisonPredicate` in TERNARY operator (#4232)

### Improvements

Expand Down
9 changes: 4 additions & 5 deletions Sources/Sentry/SentryPredicateDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ - (NSString *)expressionDescription:(NSExpression *)predicate
break;
case NSConditionalExpressionType:
if (@available(macOS 10.11, *)) {
return [NSString
stringWithFormat:@"TERNARY(%@,%@,%@)",
[self comparisonPredicateDescription:(NSComparisonPredicate *)predicate.predicate],
[self expressionDescription:predicate.trueExpression],
[self expressionDescription:predicate.falseExpression]];
return [NSString stringWithFormat:@"TERNARY(%@,%@,%@)",
[self predicateDescription:predicate.predicate],
[self expressionDescription:predicate.trueExpression],
[self expressionDescription:predicate.falseExpression]];
} else {
// this is not supposed to happen, NSConditionalExpressionType was introduced in
// macOS 10.11 but we need this version check because cocoapod lint check is failing
Expand Down
5 changes: 5 additions & 0 deletions Tests/SentryTests/SentryPredicateDescriptorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class SentryPredicateDescriptorTests: XCTestCase {
assertPredicate(predicate: pred, expectedResult: "field1 == %@ AND (field3 == %@ OR field2 == %@)")
}

func test_compoundInTenary() {
let pred = NSPredicate(format: "TERNARY(field1 > 10 AND field1 < 20, 1, 0) == 1")
assertPredicate(predicate: pred, expectedResult: "TERNARY(field1 > %@ AND field1 < %@,%@,%@) == %@")
}

func test_UNKNOWN() {
let pred = NSPredicate { _, _ in
return false
Expand Down

0 comments on commit de3c570

Please sign in to comment.