Fix bug with strings that start with special chars

This commit is contained in:
Mariam Maarouf 2019-10-20 00:30:43 +02:00
parent 0444a8512e
commit 3526b390d5
2 changed files with 6 additions and 3 deletions

View File

@ -24,9 +24,12 @@ const replaceAll = () => {
} }
const escapeAndReplace = (input_word, replace_value, case_sensitive) => { 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 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) replace(regexp_input_word, replace_value)
} }

View File

@ -3,7 +3,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "InteractiveFics", "name": "InteractiveFics",
"author": "mariamrf", "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.", "description": "Replaces Y/N & other variables in Reader Insert/second person fics with words of your choice.",
"browser_action": { "browser_action": {
"default_title": "InteractiveFics", "default_title": "InteractiveFics",