Skip to content

Commit a11c6f0

Browse files
committed
Ruby: use AccessPathSyntax library
1 parent efec348 commit a11c6f0

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ predicate summaryElement(DataFlowCallable c, string input, string output, string
5959
* is currently restricted to `"BlockArgument"`.
6060
*/
6161
bindingset[c]
62-
SummaryComponent interpretComponentSpecific(string c) {
62+
SummaryComponent interpretComponentSpecific(AccessPathToken c) {
6363
c = "Receiver" and
6464
result = FlowSummary::SummaryComponent::receiver()
6565
or
@@ -76,15 +76,10 @@ SummaryComponent interpretComponentSpecific(string c) {
7676
result = FlowSummary::SummaryComponent::arrayElementUnknown()
7777
or
7878
exists(int i |
79-
c.regexpCapture("ArrayElement\\[([0-9]+)\\]", 1).toInt() = i and
79+
c.getName() = "ArrayElement" and
80+
i = AccessPath::parseInt(c.getAnArgument()) and
8081
result = FlowSummary::SummaryComponent::arrayElementKnown(i)
8182
)
82-
or
83-
exists(int i1, int i2 |
84-
c.regexpCapture("ArrayElement\\[([-0-9]+)\\.\\.([0-9]+)\\]", 1).toInt() = i1 and
85-
c.regexpCapture("ArrayElement\\[([-0-9]+)\\.\\.([0-9]+)\\]", 2).toInt() = i2 and
86-
result = FlowSummary::SummaryComponent::arrayElementKnown([i1 .. i2])
87-
)
8883
}
8984

9085
/** Gets the textual representation of a summary component in the format used for flow summaries. */
@@ -172,25 +167,14 @@ module ParsePositions {
172167
)
173168
}
174169

175-
bindingset[s]
176-
private int parsePosition(string s) {
177-
result = s.regexpCapture("([-0-9]+)", 1).toInt()
178-
or
179-
exists(int n1, int n2 |
180-
s.regexpCapture("([-0-9]+)\\.\\.([0-9]+)", 1).toInt() = n1 and
181-
s.regexpCapture("([-0-9]+)\\.\\.([0-9]+)", 2).toInt() = n2 and
182-
result in [n1 .. n2]
183-
)
184-
}
185-
186170
predicate isParsedParameterPosition(string c, int i) {
187171
isParamBody(c) and
188-
i = parsePosition(c)
172+
i = AccessPath::parseInt(c)
189173
}
190174

191175
predicate isParsedArgumentPosition(string c, int i) {
192176
isArgBody(c) and
193-
i = parsePosition(c)
177+
i = AccessPath::parseInt(c)
194178
}
195179
}
196180

0 commit comments

Comments
 (0)