use StrConst instead of Bytes and Unicode

This commit is contained in:
erik-krogh
2023-03-24 11:24:34 +01:00
parent ffa3425195
commit 3cde11efc8
2 changed files with 4 additions and 14 deletions

View File

@@ -110,13 +110,10 @@ private module FindRegexMode {
deprecated class Regex = RegExp;
/** A StrConst used as a regular expression */
class RegExp extends Expr {
class RegExp extends Expr instanceof StrConst {
DataFlow::Node use;
RegExp() {
(this instanceof Bytes or this instanceof Unicode) and
this = RegExpTracking::regExpSource(use).asExpr()
}
RegExp() { this = RegExpTracking::regExpSource(use).asExpr() }
/** Gets a data-flow node where this string value is used as a regular expression. */
DataFlow::Node getAUse() { result = use }
@@ -332,11 +329,7 @@ class RegExp extends Expr {
}
/** Gets the text of this regex */
string getText() {
result = this.(Unicode).getS()
or
result = this.(Bytes).getS()
}
string getText() { result = super.getText() }
/** Gets the `i`th character of this regex */
string getChar(int i) { result = this.getText().charAt(i) }

View File

@@ -15,10 +15,7 @@ private import semmle.python.dataflow.new.DataFlow
private import semmle.python.Concepts as Concepts
/** Gets a constant string value that may be used as a regular expression. */
DataFlow::LocalSourceNode strStart() {
result.asExpr() instanceof Bytes or
result.asExpr() instanceof Unicode
}
DataFlow::Node strStart() { result.asExpr() instanceof StrConst }
private import semmle.python.regex as Regex