Skip to content

Commit f4e2c30

Browse files
authored
Merge pull request #291 from github/hvitved/regexp-multiples
Speedup `RegExp::multiples`
2 parents b51e741 + 8ac3dc2 commit f4e2c30

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ql/lib/codeql/ruby/regexp/ParseRegExp.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,18 @@ class RegExp extends AST::RegExpLiteral {
671671
}
672672

673673
predicate multiples(int start, int end, string lower, string upper) {
674-
this.getChar(start) = "{" and
675-
this.getChar(end - 1) = "}" and
676-
exists(string inner | inner = this.getText().substring(start + 1, end - 1) |
677-
inner.regexpMatch("[0-9]+") and
674+
exists(string text, string match, string inner |
675+
text = this.getText() and
676+
end = start + match.length() and
677+
inner = match.substring(1, match.length() - 1)
678+
|
679+
match = text.regexpFind("\\{[0-9]+\\}", _, start) and
678680
lower = inner and
679681
upper = lower
680682
or
681-
inner.regexpMatch("[0-9]*,[0-9]*") and
682-
exists(int commaIndex | commaIndex = inner.indexOf(",") |
683+
match = text.regexpFind("\\{[0-9]*,[0-9]*\\}", _, start) and
684+
exists(int commaIndex |
685+
commaIndex = inner.indexOf(",") and
683686
lower = inner.prefix(commaIndex) and
684687
upper = inner.suffix(commaIndex + 1)
685688
)

0 commit comments

Comments
 (0)