diff --git a/python/ql/src/semmle/python/regex.qll b/python/ql/src/semmle/python/regex.qll index 080771cbabfd..cc33b2b347c3 100644 --- a/python/ql/src/semmle/python/regex.qll +++ b/python/ql/src/semmle/python/regex.qll @@ -497,8 +497,12 @@ abstract class RegexString extends Expr { this.getChar(endin) = "}" and end > start and exists(string multiples | multiples = this.getText().substring(start + 1, endin) | + multiples.regexpMatch("0+") and maybe_empty = true + or multiples.regexpMatch("0*,[0-9]*") and maybe_empty = true or + multiples.regexpMatch("0*[1-9][0-9]*") and maybe_empty = false + or multiples.regexpMatch("0*[1-9][0-9]*,[0-9]*") and maybe_empty = false ) and not exists(int mid | @@ -643,9 +647,13 @@ abstract class RegexString extends Expr { start = 0 and end = this.getText().length() or exists(int y | this.lastPart(start, y) | - this.emptyMatchAtEndGroup(end, y) or - this.qualifiedItem(end, y, true) or + this.emptyMatchAtEndGroup(end, y) + or + this.qualifiedItem(end, y, true) + or this.specialCharacter(end, y, "$") + or + y = end + 2 and this.escapingChar(end) and this.getChar(end + 1) = "Z" ) or exists(int x | diff --git a/python/ql/test/library-tests/regex/Characters.expected b/python/ql/test/library-tests/regex/Characters.expected index 61d13b7bf59b..373a6bf7a662 100644 --- a/python/ql/test/library-tests/regex/Characters.expected +++ b/python/ql/test/library-tests/regex/Characters.expected @@ -110,7 +110,6 @@ | ax{3,} | 5 | 6 | | ax{3} | 0 | 1 | | ax{3} | 1 | 2 | -| ax{3} | 2 | 3 | | ax{3} | 3 | 4 | | ax{3} | 4 | 5 | | ax{,3} | 0 | 1 | diff --git a/python/ql/test/library-tests/regex/FirstLast.expected b/python/ql/test/library-tests/regex/FirstLast.expected index cdea10fac051..974504bfc4a2 100644 --- a/python/ql/test/library-tests/regex/FirstLast.expected +++ b/python/ql/test/library-tests/regex/FirstLast.expected @@ -84,6 +84,8 @@ | ax{3,} | last | 1 | 6 | | ax{3,} | last | 5 | 6 | | ax{3} | first | 0 | 1 | +| ax{3} | last | 1 | 2 | +| ax{3} | last | 1 | 5 | | ax{3} | last | 4 | 5 | | ax{,3} | first | 0 | 1 | | ax{,3} | last | 0 | 1 | diff --git a/python/ql/test/library-tests/regex/Qualified.expected b/python/ql/test/library-tests/regex/Qualified.expected index d3cf69b986f3..30019f943eb9 100644 --- a/python/ql/test/library-tests/regex/Qualified.expected +++ b/python/ql/test/library-tests/regex/Qualified.expected @@ -11,4 +11,5 @@ | ^[A-Z_]+$(?