From ec45c70e23ca2e4395498737dfe9c91d6d2d9a35 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Thu, 23 Apr 2020 06:54:29 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Escape=20`-`=20in=20a=20way=20that=E2=80=99?= =?UTF-8?q?s=20compatible=20with=20PCRE=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e5bb9db..387c561 100644 --- a/index.js +++ b/index.js @@ -9,5 +9,5 @@ module.exports = string => { // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') - .replace(/-/g, '\\u002d'); + .replace(/-/g, '\\x2d'); }; diff --git a/test.js b/test.js index fe5f549..e50f40b 100644 --- a/test.js +++ b/test.js @@ -8,10 +8,10 @@ test('main', t => { ); }); -test('escapes `-`', t => { +test('escapes `-` in a way compatible with PCRE', t => { t.is( escapeStringRegexp('foo - bar'), - 'foo \\u002d bar' + 'foo \\x2d bar' ); }); From 71083e89129bcf72a10656508de5442d3f97966d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 23 Apr 2020 14:55:51 +0800 Subject: [PATCH 2/2] 4.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f313f2..c6eb4a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "escape-string-regexp", - "version": "3.0.0", + "version": "4.0.0", "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp",