From b60ea74e8a59eb30b4e6d5759192c1629543e3d4 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Thu, 26 Nov 2020 16:58:37 +0100 Subject: [PATCH] Treat conditional expressions as if-then-else --- ql/src/codeql_ruby/controlflow/internal/AstNodes.qll | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ql/src/codeql_ruby/controlflow/internal/AstNodes.qll b/ql/src/codeql_ruby/controlflow/internal/AstNodes.qll index 3692e3473f3..0f56af92ab6 100644 --- a/ql/src/codeql_ruby/controlflow/internal/AstNodes.qll +++ b/ql/src/codeql_ruby/controlflow/internal/AstNodes.qll @@ -40,7 +40,7 @@ class LogicalOrAstNode extends Binary { AstNode getAnOperand() { result in [left, right] } } -private class If_or_elisif = @if or @elsif; +private class If_or_elisif = @if or @elsif or @conditional; class IfElsifAstNode extends AstNode, If_or_elisif { AstNode getConditionNode() { none() } @@ -66,6 +66,14 @@ private class ElsifAstNode extends IfElsifAstNode, Elsif { override AstNode getAlternativeNode() { result = this.getAlternative() } } +private class ConditionalAstNode extends IfElsifAstNode, Conditional { + override AstNode getConditionNode() { result = this.getCondition() } + + override AstNode getConsequenceNode() { result = this.getConsequence() } + + override AstNode getAlternativeNode() { result = this.getAlternative() } +} + class ParenthesizedStatement extends ParenthesizedStatements { ParenthesizedStatement() { strictcount(int i | exists(this.getChild(i))) = 1 }