Skip to content

Commit

Permalink
Bugfix Regex's containing (\0) (babel#733)
Browse files Browse the repository at this point in the history
* Bugfix Regex containing (\0)

* test for \0 in regex
  • Loading branch information
jogibear9988 authored and boopathi committed Nov 27, 2017
1 parent 8c28e1d commit f7ff978
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,14 @@ describe("transform-regexp-constructors-plugin", () => {
var x = /\/x\//;
`
);

thePlugin(
"should keep NUL",
String.raw`
var x = new RegExp('\0');
`,
String.raw`
var x = /\0/;
`
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function createRegExpLiteral(args, prettify, t) {
.replace(/\f/g, "\\f")
.replace(/\r/g, "\\r");
}

pattern = pattern.replace(/\0/g, "\\0");

return t.regExpLiteral(pattern, flags);
}

Expand Down

0 comments on commit f7ff978

Please sign in to comment.