From 7683e30b181c2b71c6fe05cbeba814e36af8f1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20K=C3=BChner?= Date: Sun, 19 Nov 2017 10:15:33 +0100 Subject: [PATCH 1/2] Bugfix Regex containing (\0) --- .../babel-plugin-transform-regexp-constructors/src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/babel-plugin-transform-regexp-constructors/src/index.js b/packages/babel-plugin-transform-regexp-constructors/src/index.js index 6aa64a4bb..ddd35d653 100644 --- a/packages/babel-plugin-transform-regexp-constructors/src/index.js +++ b/packages/babel-plugin-transform-regexp-constructors/src/index.js @@ -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); } From f7103af312d816a2e5675a85cc90e0dd3f869de3 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Thu, 23 Nov 2017 14:55:48 +0100 Subject: [PATCH 2/2] test for \0 in regex --- .../__tests__/transform-regexp-constructors-test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js b/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js index a059a069d..13295fc2f 100644 --- a/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js +++ b/packages/babel-plugin-transform-regexp-constructors/__tests__/transform-regexp-constructors-test.js @@ -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/; + ` + ); });