Skip to content

Commit f122af8

Browse files
authored
Merge pull request #9741 from tausbn/python-fix-bad-join-in-regexpbackref-getgroup
Python: Fix bad join in `RegExpBackRef::getGroup`
2 parents 731f866 + 38b8640 commit f122af8

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

python/ql/lib/semmle/python/RegexTreeView.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,22 @@ class RegExpBackRef extends RegExpTerm, TRegExpBackRef {
10001000

10011001
/** Gets the capture group this back reference refers to. */
10021002
RegExpGroup getGroup() {
1003-
result.getLiteral() = this.getLiteral() and
1004-
(
1005-
result.getNumber() = this.getNumber() or
1006-
result.getName() = this.getName()
1007-
)
1003+
this.hasLiteralAndNumber(result.getLiteral(), result.getNumber()) or
1004+
this.hasLiteralAndName(result.getLiteral(), result.getName())
1005+
}
1006+
1007+
/** Join-order helper for `getGroup`. */
1008+
pragma[nomagic]
1009+
private predicate hasLiteralAndNumber(RegExpLiteral literal, int number) {
1010+
literal = this.getLiteral() and
1011+
number = this.getNumber()
1012+
}
1013+
1014+
/** Join-order helper for `getGroup`. */
1015+
pragma[nomagic]
1016+
private predicate hasLiteralAndName(RegExpLiteral literal, string name) {
1017+
literal = this.getLiteral() and
1018+
name = this.getName()
10081019
}
10091020

10101021
override RegExpTerm getChild(int i) { none() }

0 commit comments

Comments
 (0)