Skip to content

Commit b56545b

Browse files
committed
Python: Regexp: Handle repetions {n} (with no ,)
1 parent 8d41ce1 commit b56545b

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

python/ql/src/semmle/python/regex.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,12 @@ abstract class RegexString extends Expr {
472472
this.getChar(endin) = "}" and
473473
end > start and
474474
exists(string multiples | multiples = this.getText().substring(start + 1, endin) |
475+
multiples.regexpMatch("0+") and maybe_empty = true
476+
or
475477
multiples.regexpMatch("0*,[0-9]*") and maybe_empty = true
476478
or
479+
multiples.regexpMatch("0*[1-9][0-9]*") and maybe_empty = false
480+
or
477481
multiples.regexpMatch("0*[1-9][0-9]*,[0-9]*") and maybe_empty = false
478482
) and
479483
not exists(int mid |
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.py:41:12:41:18 | Str | This regular expression includes duplicate character 'A' in a set of characters. |
2-
| test.py:42:12:42:19 | Str | This regular expression includes duplicate character '0' in a set of characters. |
3-
| test.py:43:12:43:21 | Str | This regular expression includes duplicate character '-' in a set of characters. |
1+
| test.py:44:12:44:18 | Str | This regular expression includes duplicate character 'A' in a set of characters. |
2+
| test.py:45:12:45:19 | Str | This regular expression includes duplicate character '0' in a set of characters. |
3+
| test.py:46:12:46:21 | Str | This regular expression includes duplicate character '-' in a set of characters. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| test.py:4:12:4:19 | Str | This regular expression includes an unmatchable caret at offset 1. |
22
| test.py:5:12:5:23 | Str | This regular expression includes an unmatchable caret at offset 5. |
33
| test.py:6:12:6:21 | Str | This regular expression includes an unmatchable caret at offset 2. |
4-
| test.py:74:12:74:27 | Str | This regular expression includes an unmatchable caret at offset 8. |
4+
| test.py:77:12:77:27 | Str | This regular expression includes an unmatchable caret at offset 8. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| test.py:29:12:29:19 | Str | This regular expression includes an unmatchable dollar at offset 3. |
22
| test.py:30:12:30:23 | Str | This regular expression includes an unmatchable dollar at offset 3. |
33
| test.py:31:12:31:20 | Str | This regular expression includes an unmatchable dollar at offset 2. |
4-
| test.py:75:12:75:26 | Str | This regular expression includes an unmatchable dollar at offset 3. |
4+
| test.py:78:12:78:26 | Str | This regular expression includes an unmatchable dollar at offset 3. |

python/ql/test/query-tests/Expressions/Regex/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
re.compile(b"\$ ")
3636
re.compile(b"abc$(?m)")
3737
re.compile(b"abc$()")
38+
re.compile(b"((a$)|b)*")
39+
re.compile(b"((a$)|b){4}")
40+
re.compile(b"((a$).*)")
3841

3942

4043
#Duplicate character in set

0 commit comments

Comments
 (0)