Skip to content

Commit

Permalink
Fix for NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Sep 20, 2021
1 parent 52e6e00 commit 9ce5f47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/prefer-regex-literals.js
Expand Up @@ -286,7 +286,7 @@ module.exports = {
let regexContent = getStringValue(node.arguments[0], scope);

if (regexContent && !isStringRawTaggedStaticTemplateLiteral(node.arguments[0])) {
regexContent = regexContent.replace(/\r/gu, "\\r").replace(/\n/gu, "\\n").replace(/\t/gu, "\\t").replace(/\f/gu, "\\f").replace(/\v/gu, "\\v");
regexContent = regexContent.replace(/\r/gu, "\\r").replace(/\n/gu, "\\n").replace(/\t/gu, "\\t").replace(/\f/gu, "\\f").replace(/\v/gu, "\\v").replace(/\0/gu, "\\0");
}

const newRegExpValue = `/${regexContent || "(?:)"}/${getStringValue(node.arguments[1], scope) || ""}`;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/prefer-regex-literals.js
Expand Up @@ -502,6 +502,11 @@ ruleTester.run("prefer-regex-literals", rule, {
output: "/\\0\\0/;",
errors: [{ messageId: "unexpectedRegExp" }]
},
{
code: "new RegExp('\\0\\0', 'g');",
output: "/\\0\\0/g;",
errors: [{ messageId: "unexpectedRegExp" }]
},
{
code: "RegExp('\\\\0\\\\0\\\\0', '')",
output: "/\\0\\0\\0/",
Expand Down

0 comments on commit 9ce5f47

Please sign in to comment.