From 43956137752954392ac1b93ac07ba0df40478d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=BCrkan=20YALAMAN?= Date: Sun, 24 Jul 2016 21:08:28 +0300 Subject: [PATCH] Chore: Updated no-control-regex tests to cover all cases (fixes #6438) toString prints out different outputs for /\x01/ and "/\x01/". Because of that behavior, no-control-regex rule was broken before(fixed on 141b778). During the fix I added a test to cover the case I wrote for fix. Which was also passing when the fix was not there. The test was on a string literal unfortunately which was not covering the test case where regex is written on a literal (like /\x01/). Changed the tests to make sure it covers the literal regex's as expected. --- tests/lib/rules/no-control-regex.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lib/rules/no-control-regex.js b/tests/lib/rules/no-control-regex.js index 8fc3a946364..aece04d0e99 100644 --- a/tests/lib/rules/no-control-regex.js +++ b/tests/lib/rules/no-control-regex.js @@ -21,6 +21,7 @@ var ruleTester = new RuleTester(); ruleTester.run("no-control-regex", rule, { valid: [ "var regex = /x1f/", + "var regex =" + /\\x1f/, "var regex = new RegExp('x1f')", "var regex = RegExp('x1f')", "new RegExp('[')", @@ -28,8 +29,8 @@ ruleTester.run("no-control-regex", rule, { "new (function foo(){})('\\x1f')" ], invalid: [ - { code: "var regex = /\x1f/", errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] }, - { code: "var regex = /\\\x1f/", errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] }, + { code: "var regex = " + /\x1f/, errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] }, // eslint-disable-line no-control-regex + { code: "var regex = " + /\\\x1f/, errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] }, // eslint-disable-line no-control-regex { code: "var regex = new RegExp('\\x1f')", errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] }, { code: "var regex = RegExp('\\x1f')", errors: [{ message: "Unexpected control character in regular expression.", type: "Literal"}] } ]