mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
refactor isInterpretedAsRegExp to directly work on a DataFlow node
This commit is contained in:
@@ -818,23 +818,23 @@ predicate isInterpretedAsRegExp(DataFlow::Node source) {
|
||||
source = DataFlow::globalVarRef("RegExp").getAnInvocation().getArgument(0)
|
||||
or
|
||||
// The argument of a call that coerces the argument to a regular expression.
|
||||
exists(MethodCallExpr mce, string methodName |
|
||||
exists(DataFlow::MethodCallNode mce, string methodName |
|
||||
mce.getReceiver().analyze().getAType() = TTString() and
|
||||
mce.getMethodName() = methodName and
|
||||
not exists(Function func |
|
||||
func = any(DataFlow::MethodCallNode call | call.getEnclosingExpr() = mce).getACallee()
|
||||
func = mce.getACallee()
|
||||
|
|
||||
not isNativeStringMethod(func, methodName)
|
||||
)
|
||||
|
|
||||
methodName = "match" and source.asExpr() = mce.getArgument(0) and mce.getNumArgument() = 1
|
||||
methodName = "match" and source = mce.getArgument(0) and mce.getNumArgument() = 1
|
||||
or
|
||||
methodName = "search" and
|
||||
source.asExpr() = mce.getArgument(0) and
|
||||
source = mce.getArgument(0) and
|
||||
mce.getNumArgument() = 1 and
|
||||
// "search" is a common method name, and so we exclude chained accesses
|
||||
// because `String.prototype.search` returns a number
|
||||
not exists(PropAccess p | p.getBase() = mce)
|
||||
not exists(PropAccess p | p.getBase() = mce.getEnclosingExpr())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user