You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @description Calling 'String.prototype.replace' or 'String.prototype.split' with a string argument that looks like a regular expression is probably a mistake because the called function will not convert the string into a regular expression.
* @kind problem
* @problem.severity warning
* @id js/string-instead-of-regex
* @tags quality
* reliability
* correctness
* @precision high
*/
import javascript
/**
* Gets a regular expression pattern that matches the syntax of likely regular expressions.
*/
privatestringgetALikelyRegExpPattern(){
result=
[
"/.*/[gimuy]{1,5}",// pattern with at least one flag: /foo/i
"/\\^.*/[gimuy]{0,5}",// pattern with anchor: /^foo/
"/.*\\$/[gimuy]{0,5}",// pattern with anchor: /foo$/
"\\^.*\\$",// pattern body with anchors: ^foo$
".*(?<!\\\\)\\\\[dDwWsSB].*",// contains a builtin character class: \s
".*(?<!\\\\)\\\\[\\[\\]()*+?{}|^$.].*",// contains an escaped meta-character: \(
".*\\[\\^?[\\p{Alnum}\\p{Blank}_-]+\\][*+].*"// contains a quantified custom character class: [^a-zA-Z123]+
]
}
/**
* Holds if `mce` is a call to String.prototype.replace or String.prototype.split