Skip to content

Commit c0043eb

Browse files
committed
Python: Don't treat re.escape(...) as a regex
Fixes github#3712
1 parent 7601bd4 commit c0043eb

File tree

5 files changed

+2
-87
lines changed

5 files changed

+2
-87
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ predicate used_as_regex(Expr s, string mode) {
2828
/* Call to re.xxx(regex, ... [mode]) */
2929
exists(CallNode call, string name |
3030
call.getArg(0).refersTo(_, _, s.getAFlowNode()) and
31-
call.getFunction().pointsTo(Module::named("re").attr(name))
31+
call.getFunction().pointsTo(Module::named("re").attr(name)) and
32+
not name = "escape"
3233
|
3334
mode = "None"
3435
or

python/ql/test/library-tests/regex/Characters.expected

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -118,47 +118,6 @@
118118
| ax{,3} | 3 | 4 |
119119
| ax{,3} | 4 | 5 |
120120
| ax{,3} | 5 | 6 |
121-
| https://www.humblebundle.com/home/library | 0 | 1 |
122-
| https://www.humblebundle.com/home/library | 1 | 2 |
123-
| https://www.humblebundle.com/home/library | 2 | 3 |
124-
| https://www.humblebundle.com/home/library | 3 | 4 |
125-
| https://www.humblebundle.com/home/library | 4 | 5 |
126-
| https://www.humblebundle.com/home/library | 5 | 6 |
127-
| https://www.humblebundle.com/home/library | 6 | 7 |
128-
| https://www.humblebundle.com/home/library | 7 | 8 |
129-
| https://www.humblebundle.com/home/library | 8 | 9 |
130-
| https://www.humblebundle.com/home/library | 9 | 10 |
131-
| https://www.humblebundle.com/home/library | 10 | 11 |
132-
| https://www.humblebundle.com/home/library | 11 | 12 |
133-
| https://www.humblebundle.com/home/library | 12 | 13 |
134-
| https://www.humblebundle.com/home/library | 13 | 14 |
135-
| https://www.humblebundle.com/home/library | 14 | 15 |
136-
| https://www.humblebundle.com/home/library | 15 | 16 |
137-
| https://www.humblebundle.com/home/library | 16 | 17 |
138-
| https://www.humblebundle.com/home/library | 17 | 18 |
139-
| https://www.humblebundle.com/home/library | 18 | 19 |
140-
| https://www.humblebundle.com/home/library | 19 | 20 |
141-
| https://www.humblebundle.com/home/library | 20 | 21 |
142-
| https://www.humblebundle.com/home/library | 21 | 22 |
143-
| https://www.humblebundle.com/home/library | 22 | 23 |
144-
| https://www.humblebundle.com/home/library | 23 | 24 |
145-
| https://www.humblebundle.com/home/library | 24 | 25 |
146-
| https://www.humblebundle.com/home/library | 25 | 26 |
147-
| https://www.humblebundle.com/home/library | 26 | 27 |
148-
| https://www.humblebundle.com/home/library | 27 | 28 |
149-
| https://www.humblebundle.com/home/library | 28 | 29 |
150-
| https://www.humblebundle.com/home/library | 29 | 30 |
151-
| https://www.humblebundle.com/home/library | 30 | 31 |
152-
| https://www.humblebundle.com/home/library | 31 | 32 |
153-
| https://www.humblebundle.com/home/library | 32 | 33 |
154-
| https://www.humblebundle.com/home/library | 33 | 34 |
155-
| https://www.humblebundle.com/home/library | 34 | 35 |
156-
| https://www.humblebundle.com/home/library | 35 | 36 |
157-
| https://www.humblebundle.com/home/library | 36 | 37 |
158-
| https://www.humblebundle.com/home/library | 37 | 38 |
159-
| https://www.humblebundle.com/home/library | 38 | 39 |
160-
| https://www.humblebundle.com/home/library | 39 | 40 |
161-
| https://www.humblebundle.com/home/library | 40 | 41 |
162121
| x\| | 0 | 1 |
163122
| x\|(?<!\\w)l | 0 | 1 |
164123
| x\|(?<!\\w)l | 6 | 8 |

python/ql/test/library-tests/regex/FirstLast.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@
9090
| ax{,3} | last | 1 | 2 |
9191
| ax{,3} | last | 1 | 6 |
9292
| ax{,3} | last | 5 | 6 |
93-
| https://www.humblebundle.com/home/library | first | 0 | 1 |
94-
| https://www.humblebundle.com/home/library | last | 40 | 41 |
9593
| x\| | first | 0 | 1 |
9694
| x\| | last | 0 | 1 |
9795
| x\|(?<!\\w)l | first | 0 | 1 |

python/ql/test/library-tests/regex/Regex.expected

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -218,48 +218,6 @@
218218
| ax{,3} | char | 5 | 6 |
219219
| ax{,3} | qualified | 1 | 6 |
220220
| ax{,3} | sequence | 0 | 6 |
221-
| https://www.humblebundle.com/home/library | . | 11 | 12 |
222-
| https://www.humblebundle.com/home/library | . | 24 | 25 |
223-
| https://www.humblebundle.com/home/library | char | 0 | 1 |
224-
| https://www.humblebundle.com/home/library | char | 1 | 2 |
225-
| https://www.humblebundle.com/home/library | char | 2 | 3 |
226-
| https://www.humblebundle.com/home/library | char | 3 | 4 |
227-
| https://www.humblebundle.com/home/library | char | 4 | 5 |
228-
| https://www.humblebundle.com/home/library | char | 5 | 6 |
229-
| https://www.humblebundle.com/home/library | char | 6 | 7 |
230-
| https://www.humblebundle.com/home/library | char | 7 | 8 |
231-
| https://www.humblebundle.com/home/library | char | 8 | 9 |
232-
| https://www.humblebundle.com/home/library | char | 9 | 10 |
233-
| https://www.humblebundle.com/home/library | char | 10 | 11 |
234-
| https://www.humblebundle.com/home/library | char | 12 | 13 |
235-
| https://www.humblebundle.com/home/library | char | 13 | 14 |
236-
| https://www.humblebundle.com/home/library | char | 14 | 15 |
237-
| https://www.humblebundle.com/home/library | char | 15 | 16 |
238-
| https://www.humblebundle.com/home/library | char | 16 | 17 |
239-
| https://www.humblebundle.com/home/library | char | 17 | 18 |
240-
| https://www.humblebundle.com/home/library | char | 18 | 19 |
241-
| https://www.humblebundle.com/home/library | char | 19 | 20 |
242-
| https://www.humblebundle.com/home/library | char | 20 | 21 |
243-
| https://www.humblebundle.com/home/library | char | 21 | 22 |
244-
| https://www.humblebundle.com/home/library | char | 22 | 23 |
245-
| https://www.humblebundle.com/home/library | char | 23 | 24 |
246-
| https://www.humblebundle.com/home/library | char | 25 | 26 |
247-
| https://www.humblebundle.com/home/library | char | 26 | 27 |
248-
| https://www.humblebundle.com/home/library | char | 27 | 28 |
249-
| https://www.humblebundle.com/home/library | char | 28 | 29 |
250-
| https://www.humblebundle.com/home/library | char | 29 | 30 |
251-
| https://www.humblebundle.com/home/library | char | 30 | 31 |
252-
| https://www.humblebundle.com/home/library | char | 31 | 32 |
253-
| https://www.humblebundle.com/home/library | char | 32 | 33 |
254-
| https://www.humblebundle.com/home/library | char | 33 | 34 |
255-
| https://www.humblebundle.com/home/library | char | 34 | 35 |
256-
| https://www.humblebundle.com/home/library | char | 35 | 36 |
257-
| https://www.humblebundle.com/home/library | char | 36 | 37 |
258-
| https://www.humblebundle.com/home/library | char | 37 | 38 |
259-
| https://www.humblebundle.com/home/library | char | 38 | 39 |
260-
| https://www.humblebundle.com/home/library | char | 39 | 40 |
261-
| https://www.humblebundle.com/home/library | char | 40 | 41 |
262-
| https://www.humblebundle.com/home/library | sequence | 0 | 41 |
263221
| x\| | char | 0 | 1 |
264222
| x\| | choice | 0 | 2 |
265223
| x\| | sequence | 0 | 1 |
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
| hosttest.py:6:27:6:51 | Str | This regular expression has an unescaped '.' before 'example.com', so it might match more hosts than expected. |
2-
| hosttest.py:23:21:23:63 | Str | This regular expression has an unescaped '.' before 'humblebundle.com', so it might match more hosts than expected. |

0 commit comments

Comments
 (0)