From 27757804beabc3aac74de096d7465899ae54a373 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sat, 27 Apr 2019 06:02:55 -0400 Subject: [PATCH 1/6] Add Node.js 12 to testing (#14) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f3fa8cd..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js node_js: + - '12' - '10' - '8' From dfa9f174bb5405efceb79f04906ba0b6b379cfc7 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 28 May 2019 14:36:11 +0700 Subject: [PATCH 2/6] Create funding.yml --- .github/funding.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/funding.yml diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..1a630e9 --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,3 @@ +github: sindresorhus +open_collective: sindresorhus +custom: https://sindresorhus.com/donate From 5085b257c801507460270b747f645276fbc1d937 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 31 May 2019 18:48:54 +0700 Subject: [PATCH 3/6] Tidelift tasks --- .github/funding.yml | 1 + .github/security.md | 3 +++ readme.md | 14 +++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .github/security.md diff --git a/.github/funding.yml b/.github/funding.yml index 1a630e9..5bc8a3d 100644 --- a/.github/funding.yml +++ b/.github/funding.yml @@ -1,3 +1,4 @@ github: sindresorhus open_collective: sindresorhus +tidelift: npm/escape-string-regexp custom: https://sindresorhus.com/donate diff --git a/.github/security.md b/.github/security.md new file mode 100644 index 0000000..5358dc5 --- /dev/null +++ b/.github/security.md @@ -0,0 +1,3 @@ +# Security Policy + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. diff --git a/readme.md b/readme.md index 157472b..03b1b31 100644 --- a/readme.md +++ b/readme.md @@ -24,6 +24,14 @@ new RegExp(escapedString); You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+
From 732905da074f0220487ad6a27590f89bd0819374 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Tue, 7 Apr 2020 09:23:17 -0700 Subject: [PATCH 4/6] =?UTF-8?q?Escape=20`-`=20in=20a=20way=20that=E2=80=99?= =?UTF-8?q?s=20compatible=20with=20Unicode=20patterns=20(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sindre Sorhus --- index.js | 8 +++++--- test.js | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 58217a4..e5bb9db 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,13 @@ 'use strict'; -const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g; - module.exports = string => { if (typeof string !== 'string') { throw new TypeError('Expected a string'); } - return string.replace(matchOperatorsRegex, '\\$&'); + // Escape characters with special meaning either inside or outside character sets. + // 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'); }; diff --git a/test.js b/test.js index 7fac094..fe5f549 100644 --- a/test.js +++ b/test.js @@ -11,6 +11,13 @@ test('main', t => { test('escapes `-`', t => { t.is( escapeStringRegexp('foo - bar'), - 'foo \\- bar' + 'foo \\u002d bar' + ); +}); + +test('escapes `-` in a way compatible with the Unicode flag', t => { + t.regex( + '-', + new RegExp(escapeStringRegexp('-'), 'u') ); }); From 70deac56293483fae272b8c4ffd76d837bf6c169 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 8 Apr 2020 00:27:51 +0800 Subject: [PATCH 5/6] Require Node.js 10 --- .travis.yml | 1 - license | 2 +- package.json | 15 +++++---------- readme.md | 3 --- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index f98fed0..94ab01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,3 @@ language: node_js node_js: - '12' - '10' - - '8' diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 2e343cf..6040f69 100644 --- a/package.json +++ b/package.json @@ -4,17 +4,14 @@ "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, - "maintainers": [ - "Sindre Sorhus (sindresorhus.com)", - "Joshua Boy Nicolai Appelman (jbna.nl)" - ], "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" @@ -27,17 +24,15 @@ "escape", "regex", "regexp", - "re", "regular", "expression", "string", - "str", "special", "characters" ], "devDependencies": { "ava": "^1.4.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "tsd": "^0.11.0", + "xo": "^0.28.3" } } diff --git a/readme.md b/readme.md index 03b1b31..2945dfc 100644 --- a/readme.md +++ b/readme.md @@ -2,14 +2,12 @@ > Escape RegExp special characters - ## Install ``` $ npm install escape-string-regexp ``` - ## Usage ```js @@ -23,7 +21,6 @@ new RegExp(escapedString); You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. - ---
From d248d827a72f75d7bafbe58097b9a5971c560df7 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 8 Apr 2020 00:29:04 +0800 Subject: [PATCH 6/6] 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6040f69..5f313f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "escape-string-regexp", - "version": "2.0.0", + "version": "3.0.0", "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp",