Skip to content

Commit 21b4918

Browse files
committed
Ruby: Add getPositionalArgument
This gets positional arguments from a call. These are arguments which are not keyword arguments.
1 parent d4f7f2b commit 21b4918

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,14 @@ module ExprNodes {
357357
)
358358
}
359359

360+
/**
361+
* Gets the `nth` positional argument of this call.
362+
* Unlike `getArgument`, this excludes keyword arguments.
363+
*/
364+
final ExprCfgNode getPositionalArgument(int n) {
365+
result = this.getArgument(n) and not result instanceof PairCfgNode
366+
}
367+
360368
/** Gets the number of arguments of this call. */
361369
final int getNumberOfArguments() { result = e.getNumberOfArguments() }
362370

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class CallNode extends LocalSourceNode, ExprNode {
7171
/** Gets the data-flow node corresponding to the named argument of the call corresponding to this data-flow node */
7272
ExprNode getKeywordArgument(string name) { result.getExprNode() = node.getKeywordArgument(name) }
7373

74+
/**
75+
* Gets the `nth` positional argument of this call.
76+
* Unlike `getArgument`, this excludes keyword arguments.
77+
*/
78+
final ExprNode getPositionalArgument(int n) {
79+
result.getExprNode() = node.getPositionalArgument(n)
80+
}
81+
7482
/** Gets the name of the the method called by the method call (if any) corresponding to this data-flow node */
7583
string getMethodName() { result = node.getExpr().(MethodCall).getMethodName() }
7684

0 commit comments

Comments
 (0)