noControlCharactersInRegex
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noControlCharactersInRegex¥Diagnostic Category:
lint/suspicious/noControlCharactersInRegex -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-control-regex相同¥Same as
no-control-regex
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noControlCharactersInRegex": "error" } } }}¥Description
防止正则表达式字面量中包含控制字符和某些与控制字符匹配的转义序列。
¥Prevents from having control characters and some escape sequences that match control characters in regular expression literals.
控制字符是隐藏的特殊字符,在 ASCII 系统中编号为 0 到 31。它们在 JavaScript 文本中不常用。所以,如果你在模式(称为正则表达式)中看到它们,那可能是一个错误。
¥Control characters are hidden special characters that are numbered from 0 to 31 in the ASCII system. They’re not commonly used in JavaScript text. So, if you see them in a pattern (called a regular expression), it’s probably a mistake.
正则表达式模式的以下元素被视为可能出现的输入错误,因此本规则不允许:
¥The following elements of regular expression patterns are considered possible errors in typing and are therefore disallowed by this rule:
-
十六进制字符转义从
\x00到\x1F¥Hexadecimal character escapes from
\x00to\x1F -
从
\u0000到\u001F的 Unicode 字符转义¥Unicode character escapes from
\u0000to\u001F -
从
\u{0}到\u{1F}的 Unicode 代码点转义¥Unicode code point escapes from
\u{0}to\u{1F} -
从 U+0000 到 U+001F 的未转义原始字符
¥Unescaped raw characters from U+0000 to U+001F
此规则允许使用 \t 和 \n 等控制转义。
¥Control escapes such as \t and \n are allowed by this rule.
¥Examples
¥Invalid
var pattern1 = /\x00/;code-block.js:1:18 lint/suspicious/noControlCharactersInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected control character in a regular expression.
> 1 │ var pattern1 = /\x00/;
│ ^^^^
2 │
ℹ Control characters are unusual and potentially incorrect inputs, so they are disallowed.
var pattern2 = /\x0C/;code-block.js:1:18 lint/suspicious/noControlCharactersInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected control character in a regular expression.
> 1 │ var pattern2 = /\x0C/;
│ ^^^^
2 │
ℹ Control characters are unusual and potentially incorrect inputs, so they are disallowed.
var pattern3 = /\x1F/;code-block.js:1:18 lint/suspicious/noControlCharactersInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected control character in a regular expression.
> 1 │ var pattern3 = /\x1F/;
│ ^^^^
2 │
ℹ Control characters are unusual and potentially incorrect inputs, so they are disallowed.
var pattern4 = /\u000C/;code-block.js:1:18 lint/suspicious/noControlCharactersInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected control character in a regular expression.
> 1 │ var pattern4 = /\u000C/;
│ ^^^^^^
2 │
ℹ Control characters are unusual and potentially incorrect inputs, so they are disallowed.
var pattern5 = /\u{C}/u;code-block.js:1:18 lint/suspicious/noControlCharactersInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected control character in a regular expression.
> 1 │ var pattern5 = /\u{C}/u;
│ ^^^^^
2 │
ℹ Control characters are unusual and potentially incorrect inputs, so they are disallowed.
¥Valid
var pattern1 = /\x20/;var pattern2 = /\u0020/;var pattern3 = /\u{20}/u;var pattern4 = /\t/;var pattern5 = /\n/;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号