From dc0dbbb7dceb045e232148c58e8ca48f083edc1d Mon Sep 17 00:00:00 2001 From: Nikita Suhov Date: Tue, 6 Mar 2018 16:58:03 +0700 Subject: [PATCH] Escape every key before making Regexp, so keys will be without any special characters for RegExp. So 'values' object is only for literal string replacement. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index af1584a..28620be 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,7 +49,7 @@ class ReplaceText { const vals = this.values; const pats = this.patterns; const keys = Object.keys(vals).filter(k => !/[ex,in]clude|patterns/.test(k)); - const RGXP = new RegExp(keys.join('|'), 'g'); + const RGXP = new RegExp(keys.map(k => k.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")).join('|'), 'g'); const isMatch = this.isMatch; compiler.plugin('compilation', bundle => {