Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: exclude \u000d so new line won't convert to text (fixes #12027) (
  • Loading branch information
zamboney authored and mysticatea committed Sep 29, 2019
1 parent e85d27a commit d592a24
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rule-tester/rule-tester.js
Expand Up @@ -130,7 +130,7 @@ function freezeDeeply(x) {
*/
function sanitize(text) {
return text.replace(
/[\u0000-\u001f]/gu, // eslint-disable-line no-control-regex
/[\u0000-\u0009|\u000b-\u001a]/gu, // eslint-disable-line no-control-regex

This comment has been minimized.

Copy link
@m0dul3
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
);
}
Expand Down
54 changes: 53 additions & 1 deletion tests/lib/rule-tester/rule-tester.js
Expand Up @@ -324,7 +324,11 @@ describe("RuleTester", () => {
"bar = baz;"
],
invalid: [
{ code: "var foo = bar; var qux = boop;", output: null, errors: 2 }
{
code: "var foo = bar; var qux = boop;",
output: null,
errors: 2
}
]
});
}, /Expected no autofixes to be suggested/u);
Expand Down Expand Up @@ -1072,4 +1076,52 @@ describe("RuleTester", () => {
);
}, /A fatal parsing error occurred in autofix/u);
});

describe("sanitize test cases", () => {
let originalRuleTesterIt;
let spyRuleTesterIt;

before(() => {
originalRuleTesterIt = RuleTester.it;
spyRuleTesterIt = sinon.spy();
RuleTester.it = spyRuleTesterIt;
});
after(() => {
RuleTester.it = originalRuleTesterIt;
});
beforeEach(() => {
spyRuleTesterIt.resetHistory();
ruleTester = new RuleTester();
});
it("should present newline when using back-tick as new line", () => {
const code = `
var foo = bar;`;

ruleTester.run("no-var", require("../../fixtures/testers/rule-tester/no-var"), {
valid: [],
invalid: [
{
code,
errors: [/^Bad var/u]
}
]
});
sinon.assert.calledWith(spyRuleTesterIt, code);
});
it("should present \\u0000 as a string", () => {
const code = "\u0000";

ruleTester.run("no-var", require("../../fixtures/testers/rule-tester/no-var"), {
valid: [],
invalid: [
{
code,
errors: [/^Bad var/u]
}
]
});
sinon.assert.calledWith(spyRuleTesterIt, "\\u0000");
});

});
});

0 comments on commit d592a24

Please sign in to comment.