From 3cde11efc8f17baa8f7d7087fa136397ca0d21bd Mon Sep 17 00:00:00 2001 From: erik-krogh Date: Fri, 24 Mar 2023 11:24:34 +0100 Subject: [PATCH] use StrConst instead of Bytes and Unicode --- .../semmle/python/regexp/internal/ParseRegExp.qll | 13 +++---------- .../python/regexp/internal/RegExpTracking.qll | 5 +---- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll b/python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll index 65e7ea93bae..f635332944b 100644 --- a/python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll +++ b/python/ql/lib/semmle/python/regexp/internal/ParseRegExp.qll @@ -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) } diff --git a/python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll b/python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll index fb67f0e8c2c..b62e975cf82 100644 --- a/python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll +++ b/python/ql/lib/semmle/python/regexp/internal/RegExpTracking.qll @@ -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