From 3526b390d580e7f75ff1d6a29870a16df8da63af Mon Sep 17 00:00:00 2001 From: Mariam Maarouf Date: Sun, 20 Oct 2019 00:30:43 +0200 Subject: [PATCH] Fix bug with strings that start with special chars --- content_script.js | 7 +++++-- manifest.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/content_script.js b/content_script.js index c72581e..44dc8f7 100644 --- a/content_script.js +++ b/content_script.js @@ -24,9 +24,12 @@ const replaceAll = () => { } const escapeAndReplace = (input_word, replace_value, case_sensitive) => { - const input_word_escaped = escapeRegExp(input_word.trim()) + let input_word_escaped = escapeRegExp(input_word.trim()) const flags = case_sensitive ? "g" : "ig" - const regexp_input_word = new RegExp(`\\b${input_word_escaped}\\b`, flags) + if (!input_word_escaped.startsWith('\\')) { + input_word_escaped = `\\b${input_word_escaped}\\b` + } + const regexp_input_word = new RegExp(input_word_escaped, flags) replace(regexp_input_word, replace_value) } diff --git a/manifest.json b/manifest.json index 21cc8b9..7ea4ef3 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "manifest_version": 2, "name": "InteractiveFics", "author": "mariamrf", - "version": "5.0", + "version": "5.0.1", "description": "Replaces Y/N & other variables in Reader Insert/second person fics with words of your choice.", "browser_action": { "default_title": "InteractiveFics",