Skip to content

Commit aafef38

Browse files
committed
refactor StringPercentCall#getFormatArgument
1 parent c13e8e4 commit aafef38

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ruby/ql/lib/codeql/ruby/frameworks/StringFormatters.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ class StringPercentCall extends PrintfStyleCall {
8787
override DataFlow::Node getFormatString() { result = this.getReceiver() }
8888

8989
override DataFlow::Node getFormatArgument(int n) {
90-
exists(DataFlow::CallNode arrCall |
91-
arrCall = this.getArgument(0) and arrCall.getMethodName() = "[]"
92-
|
93-
n = -2 and // -2 is indicates that the index does not make sense in this context
94-
result = arrCall.getKeywordArgument(_)
90+
exists(Ast::Call call | call = this.asExpr().getExpr() |
91+
exists(Ast::ArrayLiteral arrLit | arrLit = call.getArgument(0) |
92+
result.asExpr().getExpr() = arrLit.getElement(n)
93+
)
9594
or
96-
result = arrCall.getArgument(n)
95+
exists(Ast::HashLiteral hashLit | hashLit = call.getArgument(0) |
96+
n = -2 and // -2 is indicates that the index does not make sense in this context
97+
result.asExpr().getExpr() = hashLit.getAnElement()
98+
)
9799
)
98100
}
99101

0 commit comments

Comments
 (0)