refactor isInterpretedAsRegExp to directly work on a DataFlow node

This commit is contained in:
Erik Krogh Kristensen
2020-01-02 11:18:14 +01:00
parent a0b5aa5ae4
commit d1a77d6993

View File

@@ -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())
)
)
}