Skip to content

Commit 8fd8c9b

Browse files
committed
Fix CallExprCfgNode.getKeywordArgument
This predicate now produces results.
1 parent 0caea17 commit 8fd8c9b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ruby/ql/lib/codeql/ruby/controlflow/CfgNodes.qll

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ module ExprNodes {
320320

321321
/** Gets the the keyword argument whose key is `keyword` of this call. */
322322
final ExprCfgNode getKeywordArgument(string keyword) {
323-
e.hasCfgChild(e.getKeywordArgument(keyword), this, result)
323+
exists(PairCfgNode n |
324+
e.hasCfgChild(e.getAnArgument(), this, n) and
325+
n.getKey().getExpr().(SymbolLiteral).getValueText() = keyword and
326+
result = n.getValue()
327+
)
324328
}
325329

326330
/** Gets the number of arguments of this call. */
@@ -426,6 +430,21 @@ module ExprNodes {
426430
ParenthesizedExprCfgNode() { this.getExpr() instanceof ParenthesizedExpr }
427431
}
428432

433+
private class PairChildMapping extends ExprChildMapping, Pair {
434+
override predicate relevantChild(Expr e) { e = this.getKey() or e = this.getValue() }
435+
}
436+
437+
/** A control-flow node that wraps a `Pair` AST expression. */
438+
class PairCfgNode extends ExprCfgNode {
439+
override PairChildMapping e;
440+
441+
final override Pair getExpr() { result = ExprCfgNode.super.getExpr() }
442+
443+
final ExprCfgNode getKey() { e.hasCfgChild(e.getKey(), this, result) }
444+
445+
final ExprCfgNode getValue() { e.hasCfgChild(e.getValue(), this, result) }
446+
}
447+
429448
/** A control-flow node that wraps a `VariableReadAccess` AST expression. */
430449
class VariableReadAccessCfgNode extends ExprCfgNode {
431450
override VariableReadAccess e;

ruby/ql/test/library-tests/controlflow/graph/Nodes.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,5 @@ positionalArguments
319319
| raise.rb:161:7:161:14 | call to raise | raise.rb:161:13:161:14 | "" |
320320
| raise.rb:168:5:168:12 | call to raise | raise.rb:168:11:168:12 | "" |
321321
keywordArguments
322+
| cfg.html.erb:6:9:6:58 | call to stylesheet_link_tag | media | cfg.html.erb:6:54:6:58 | "all" |
323+
| cfg.html.erb:12:11:12:33 | call to link_to | id | cfg.html.erb:12:31:12:33 | "a" |

0 commit comments

Comments
 (0)