File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
javascript/ql/src/semmle/javascript Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -798,6 +798,16 @@ class RegExpParseError extends Error, @regexp_parse_error {
798798 override string toString ( ) { result = getMessage ( ) }
799799}
800800
801+ /**
802+ * Holds if `func` is a method defined on `String.prototype` with name `name`.
803+ */
804+ private predicate isNativeStringMethod ( Function func , string name ) {
805+ exists ( ExternalInstanceMemberDecl decl |
806+ decl .hasQualifiedName ( "String" , name ) and
807+ func = decl .getInit ( )
808+ )
809+ }
810+
801811/**
802812 * Holds if `source` may be interpreted as a regular expression.
803813 */
@@ -811,7 +821,11 @@ predicate isInterpretedAsRegExp(DataFlow::Node source) {
811821 exists ( MethodCallExpr mce , string methodName |
812822 mce .getReceiver ( ) .analyze ( ) .getAType ( ) = TTString ( ) and
813823 mce .getMethodName ( ) = methodName and
814- not exists ( DataFlow:: FunctionNode func | func = DataFlow:: valueNode ( mce .getCallee ( ) ) .getAFunctionValue ( ) | not func .getFunction ( ) .inExternsFile ( ) )
824+ not exists ( Function func |
825+ func = any ( DataFlow:: MethodCallNode call | call .getEnclosingExpr ( ) = mce ) .getACallee ( )
826+ |
827+ not isNativeStringMethod ( func , methodName )
828+ )
815829 |
816830 methodName = "match" and source .asExpr ( ) = mce .getArgument ( 0 ) and mce .getNumArgument ( ) = 1
817831 or
You can’t perform that action at this time.
0 commit comments