Skip to content

Commit 2e78077

Browse files
committed
Python: Add a bit of regex docs
and use the canonical way of specifying a ModuleValue
1 parent 0da554c commit 2e78077

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ private predicate re_module_function(string name, int flags) {
1212
name = "subn" and flags = 4
1313
}
1414

15+
/**
16+
* Holds if `s` is used as a regex with the `re` module, with the regex-mode `mode` (if known).
17+
* If regex mode is not known, `mode` will be `"None"`.
18+
*/
1519
predicate used_as_regex(Expr s, string mode) {
1620
(s instanceof Bytes or s instanceof Unicode)
1721
and
18-
exists(ModuleValue re | re.getName() = "re" |
22+
exists(ModuleValue re | re = Module::named("re") |
1923
/* Call to re.xxx(regex, ... [mode]) */
2024
exists(CallNode call, string name |
2125
call.getArg(0).refersTo(_, _, s.getAFlowNode()) and

0 commit comments

Comments
 (0)