Skip to content

Commit d1a77d6

Browse files
committed
refactor isInterpretedAsRegExp to directly work on a DataFlow node
1 parent a0b5aa5 commit d1a77d6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

javascript/ql/src/semmle/javascript/Regexp.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,23 +818,23 @@ predicate isInterpretedAsRegExp(DataFlow::Node source) {
818818
source = DataFlow::globalVarRef("RegExp").getAnInvocation().getArgument(0)
819819
or
820820
// The argument of a call that coerces the argument to a regular expression.
821-
exists(MethodCallExpr mce, string methodName |
821+
exists(DataFlow::MethodCallNode mce, string methodName |
822822
mce.getReceiver().analyze().getAType() = TTString() and
823823
mce.getMethodName() = methodName and
824824
not exists(Function func |
825-
func = any(DataFlow::MethodCallNode call | call.getEnclosingExpr() = mce).getACallee()
825+
func = mce.getACallee()
826826
|
827827
not isNativeStringMethod(func, methodName)
828828
)
829829
|
830-
methodName = "match" and source.asExpr() = mce.getArgument(0) and mce.getNumArgument() = 1
830+
methodName = "match" and source = mce.getArgument(0) and mce.getNumArgument() = 1
831831
or
832832
methodName = "search" and
833-
source.asExpr() = mce.getArgument(0) and
833+
source = mce.getArgument(0) and
834834
mce.getNumArgument() = 1 and
835835
// "search" is a common method name, and so we exclude chained accesses
836836
// because `String.prototype.search` returns a number
837-
not exists(PropAccess p | p.getBase() = mce)
837+
not exists(PropAccess p | p.getBase() = mce.getEnclosingExpr())
838838
)
839839
)
840840
}

0 commit comments

Comments
 (0)