mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Taint branches of tainted ternary expressions (#6393)
This commit is contained in:
+4
-1
@@ -19,7 +19,10 @@
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* None.
|
||||
* Treat closures in the branches of ternary expressions as escaping
|
||||
when the whole expression is escaping in the `unneeded_escaping` rule.
|
||||
[SimplyDanny](https://github.com/SimplyDanny)
|
||||
[#6386](https://github.com/realm/SwiftLint/pull/6386)
|
||||
|
||||
## 0.63.0-rc.2: High-Speed Extraction
|
||||
|
||||
|
||||
@@ -102,6 +102,11 @@ struct UnneededEscapingRule: Rule {
|
||||
var cs = [1: c]
|
||||
}
|
||||
""", excludeFromDocumentation: true),
|
||||
Example("""
|
||||
func f(c: @escaping () -> Void) {
|
||||
f(true ? c : { })
|
||||
}
|
||||
"""),
|
||||
],
|
||||
triggeringExamples: [
|
||||
Example("""
|
||||
@@ -324,6 +329,9 @@ private final class EscapeChecker: SyntaxVisitor {
|
||||
let declRef = optChain.expression.as(DeclReferenceExprSyntax.self) {
|
||||
return taintedVariables.contains(declRef.baseName.text)
|
||||
}
|
||||
if let ternary = expr.as(TernaryExprSyntax.self) {
|
||||
return isTainted(ternary.thenExpression) || isTainted(ternary.elseExpression)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user