From 527595f79bf97bc2d17cb821c8bb6b4e8b6776f9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 25 Nov 2019 14:25:11 -0500 Subject: [PATCH] Remove unnecessary escapes from regex literals --- ext/bg/js/audio.js | 4 ++-- ext/bg/js/dictionary.js | 2 +- ext/bg/js/search.js | 4 ++-- ext/fg/js/document.js | 2 +- ext/fg/js/popup.js | 2 +- ext/mixed/js/audio.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js index 9bbbf902..dc0ba5eb 100644 --- a/ext/bg/js/audio.js +++ b/ext/bg/js/audio.js @@ -107,7 +107,7 @@ const audioUrlBuilders = { 'custom': async (definition, optionsContext) => { const options = await apiOptionsGet(optionsContext); const customSourceUrl = options.audio.customSourceUrl; - return customSourceUrl.replace(/\{([^\}]*)\}/g, (m0, m1) => (hasOwn(definition, m1) ? `${definition[m1]}` : m0)); + return customSourceUrl.replace(/\{([^}]*)\}/g, (m0, m1) => (hasOwn(definition, m1) ? `${definition[m1]}` : m0)); } }; @@ -133,7 +133,7 @@ function audioUrlNormalize(url, baseUrl, basePath) { // Begins with "/" url = baseUrl + url; } - } else if (!/^[a-z][a-z0-9\+\-\.]*:/i.test(url)) { + } else if (!/^[a-z][a-z0-9\-+.]*:/i.test(url)) { // No URI scheme => relative path url = baseUrl + basePath + url; } diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index affce9e9..409bed85 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -322,7 +322,7 @@ async function dictFieldFormat(field, definition, mode, options, exceptions) { compactGlossaries: options.general.compactGlossaries }; const markers = dictFieldFormat.markers; - const pattern = /\{([\w\-]+)\}/g; + const pattern = /\{([\w-]+)\}/g; return await stringReplaceAsync(field, pattern, async (g0, marker) => { if (!markers.has(marker)) { return g0; diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index ae76c23b..552b7a59 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -207,7 +207,7 @@ class DisplaySearch extends Display { async onSearchQueryUpdated(query, animate) { try { const details = {}; - const match = /[\*\uff0a]+$/.exec(query); + const match = /[*\uff0a]+$/.exec(query); if (match !== null) { details.wildcard = true; query = query.substring(0, query.length - match[0].length); @@ -356,7 +356,7 @@ class DisplaySearch extends Display { } static getSearchQueryFromLocation(url) { - let match = /^[^\?#]*\?(?:[^&#]*&)?query=([^&#]*)/.exec(url); + let match = /^[^?#]*\?(?:[^&#]*&)?query=([^&#]*)/.exec(url); return match !== null ? decodeURIComponent(match[1]) : null; } } diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 3dd12a40..10dea7df 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -17,7 +17,7 @@ */ -const REGEX_TRANSPARENT_COLOR = /rgba\s*\([^\)]*,\s*0(?:\.0+)?\s*\)/; +const REGEX_TRANSPARENT_COLOR = /rgba\s*\([^)]*,\s*0(?:\.0+)?\s*\)/; function docSetImposterStyle(style, propertyName, value) { style.setProperty(propertyName, value, 'important'); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index df784029..c40e5d60 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -303,7 +303,7 @@ class Popup { } static getColorInfo(cssColor) { - const m = /^\s*rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d\.]+)\s*)?\)\s*$/.exec(cssColor); + const m = /^\s*rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)\s*$/.exec(cssColor); if (m === null) { return null; } const m4 = m[4]; diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js index 7d5ffedd..35f283a4 100644 --- a/ext/mixed/js/audio.js +++ b/ext/mixed/js/audio.js @@ -68,7 +68,7 @@ class TextToSpeechAudio { } static createFromUri(ttsUri) { - const m = /^tts:[^#\?]*\?([^#]*)/.exec(ttsUri); + const m = /^tts:[^#?]*\?([^#]*)/.exec(ttsUri); if (m === null) { return null; } const searchParameters = {};