Skip to content

Commit 651f8ab

Browse files
committed
Python: Avoid multiple results for toString
1 parent 72986e1 commit 651f8ab

File tree

8 files changed

+4
-26
lines changed

8 files changed

+4
-26
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ deprecated string mode_from_mode_object(Value obj) {
121121
abstract class RegexString extends Expr {
122122
RegexString() { (this instanceof Bytes or this instanceof Unicode) }
123123

124-
override string toString() {
125-
result = this.(Bytes).getText()
126-
or
127-
result = this.(Unicode).getText()
128-
}
129-
130124
/**
131125
* Helper predicate for `char_set_start(int start, int end)`.
132126
*

python/ql/test/library-tests/regex/SubstructureTests.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CharacterSetTest extends InlineExpectationsTest {
1313
exists(Regex re, int start, int end |
1414
re.charSet(start, end) and
1515
location = re.getLocation() and
16-
element = re.toString().substring(start, end) and
16+
element = re.getText().substring(start, end) and
1717
value = start + ":" + end and
1818
tag = "charSet"
1919
)
@@ -31,7 +31,7 @@ class CharacterRangeTest extends InlineExpectationsTest {
3131
exists(Regex re, int start, int lower_end, int upper_start, int end |
3232
re.charRange(_, start, lower_end, upper_start, end) and
3333
location = re.getLocation() and
34-
element = re.toString().substring(start, end) and
34+
element = re.getText().substring(start, end) and
3535
value = start + ":" + lower_end + "-" + upper_start + ":" + end and
3636
tag = "charRange"
3737
)
@@ -49,7 +49,7 @@ class EscapeTest extends InlineExpectationsTest {
4949
exists(Regex re, int start, int end |
5050
re.escapedCharacter(start, end) and
5151
location = re.getLocation() and
52-
element = re.toString().substring(start, end) and
52+
element = re.getText().substring(start, end) and
5353
value = start + ":" + end and
5454
tag = "escapedCharacter"
5555
)
@@ -67,7 +67,7 @@ class GroupTest extends InlineExpectationsTest {
6767
exists(Regex re, int start, int end |
6868
re.group(start, end) and
6969
location = re.getLocation() and
70-
element = re.toString().substring(start, end) and
70+
element = re.getText().substring(start, end) and
7171
value = start + ":" + end and
7272
tag = "group"
7373
)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
| test.py:17:12:17:22 | Str | Backspace escape in regular expression at offset 1. |
2-
| test.py:17:12:17:22 | [\\b\\t ] | Backspace escape in regular expression at offset 1. |
3-
| test.py:19:12:19:28 | E\\d+\\b[ \\b\\t] | Backspace escape in regular expression at offset 8. |
42
| test.py:19:12:19:28 | Str | Backspace escape in regular expression at offset 8. |
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
| test.py:46:12:46:18 | Str | This regular expression includes duplicate character 'A' in a set of characters. |
2-
| test.py:46:12:46:18 | [AA] | This regular expression includes duplicate character 'A' in a set of characters. |
32
| test.py:47:12:47:19 | Str | This regular expression includes duplicate character '0' in a set of characters. |
4-
| test.py:47:12:47:19 | [000] | This regular expression includes duplicate character '0' in a set of characters. |
53
| test.py:48:12:48:21 | Str | This regular expression includes duplicate character '-' in a set of characters. |
6-
| test.py:48:12:48:21 | [-0-9-] | This regular expression includes duplicate character '-' in a set of characters. |
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
| test.py:22:12:22:29 | (P<name>[\\w]+) | Regular expression is missing '?' in named group. |
21
| test.py:22:12:22:29 | Str | Regular expression is missing '?' in named group. |
3-
| test.py:23:12:23:33 | (_(P<name>[\\w]+)\|) | Regular expression is missing '?' in named group. |
42
| test.py:23:12:23:33 | Str | Regular expression is missing '?' in named group. |
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
| test.py:4:12:4:19 | ^abc | This regular expression includes an unmatchable caret at offset 1. |
21
| test.py:4:12:4:19 | Str | This regular expression includes an unmatchable caret at offset 1. |
3-
| test.py:5:12:5:23 | (?s) ^abc | This regular expression includes an unmatchable caret at offset 5. |
42
| test.py:5:12:5:23 | Str | This regular expression includes an unmatchable caret at offset 5. |
53
| test.py:6:12:6:21 | Str | This regular expression includes an unmatchable caret at offset 2. |
6-
| test.py:6:12:6:21 | \\[^123] | This regular expression includes an unmatchable caret at offset 2. |
7-
| test.py:79:12:79:27 | (?<=foo)^\\w+ | This regular expression includes an unmatchable caret at offset 8. |
84
| test.py:79:12:79:27 | Str | This regular expression includes an unmatchable caret at offset 8. |
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
| test.py:29:12:29:19 | Str | This regular expression includes an unmatchable dollar at offset 3. |
2-
| test.py:29:12:29:19 | abc$ | This regular expression includes an unmatchable dollar at offset 3. |
32
| test.py:30:12:30:23 | Str | This regular expression includes an unmatchable dollar at offset 3. |
4-
| test.py:30:12:30:23 | abc$ (?s) | This regular expression includes an unmatchable dollar at offset 3. |
53
| test.py:31:12:31:20 | Str | This regular expression includes an unmatchable dollar at offset 2. |
6-
| test.py:31:12:31:20 | \\[$] | This regular expression includes an unmatchable dollar at offset 2. |
74
| test.py:80:12:80:26 | Str | This regular expression includes an unmatchable dollar at offset 3. |
8-
| test.py:80:12:80:26 | \\w+$(?=foo) | This regular expression includes an unmatchable dollar at offset 3. |
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
| hosttest.py:6:27:6:51 | (www\|beta).example.com/ | This regular expression has an unescaped '.' before 'example.com', so it might match more hosts than expected. |
21
| hosttest.py:6:27:6:51 | Str | This regular expression has an unescaped '.' before 'example.com', so it might match more hosts than expected. |

0 commit comments

Comments
 (0)