Skip to content

Commit

Permalink
Chore: Updated no-control-regex tests to cover all cases (fixes #6438) (
Browse files Browse the repository at this point in the history
#6752)

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.
  • Loading branch information
efegurkan authored and gyandeeps committed Jul 28, 2016
1 parent 1025772 commit ddea63a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/lib/rules/no-control-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ 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('[')",
"RegExp('[')",
"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"}] }
]
Expand Down

0 comments on commit ddea63a

Please sign in to comment.