Skip to content

Commit 3cde11e

Browse files
committed
use StrConst instead of Bytes and Unicode
1 parent ffa3425 commit 3cde11e

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@ private module FindRegexMode {
110110
deprecated class Regex = RegExp;
111111

112112
/** A StrConst used as a regular expression */
113-
class RegExp extends Expr {
113+
class RegExp extends Expr instanceof StrConst {
114114
DataFlow::Node use;
115115

116-
RegExp() {
117-
(this instanceof Bytes or this instanceof Unicode) and
118-
this = RegExpTracking::regExpSource(use).asExpr()
119-
}
116+
RegExp() { this = RegExpTracking::regExpSource(use).asExpr() }
120117

121118
/** Gets a data-flow node where this string value is used as a regular expression. */
122119
DataFlow::Node getAUse() { result = use }
@@ -332,11 +329,7 @@ class RegExp extends Expr {
332329
}
333330

334331
/** Gets the text of this regex */
335-
string getText() {
336-
result = this.(Unicode).getS()
337-
or
338-
result = this.(Bytes).getS()
339-
}
332+
string getText() { result = super.getText() }
340333

341334
/** Gets the `i`th character of this regex */
342335
string getChar(int i) { result = this.getText().charAt(i) }

python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ private import semmle.python.dataflow.new.DataFlow
1515
private import semmle.python.Concepts as Concepts
1616

1717
/** Gets a constant string value that may be used as a regular expression. */
18-
DataFlow::LocalSourceNode strStart() {
19-
result.asExpr() instanceof Bytes or
20-
result.asExpr() instanceof Unicode
21-
}
18+
DataFlow::Node strStart() { result.asExpr() instanceof StrConst }
2219

2320
private import semmle.python.regex as Regex
2421

0 commit comments

Comments
 (0)