From 21efb9d5baccc90f9cce11cdfca24161a08867e2 Mon Sep 17 00:00:00 2001 From: luckyrat Date: Wed, 7 Oct 2020 13:00:54 +0100 Subject: [PATCH] Including/excluding forms by string matching now ignores case Fixes #237 --- _locales/en/messages.json | 8 +++++++ common/ConfigManager.ts | 41 +++++++++++++++++++++++++++--------- common/DefaultSiteConfig.ts | 1 + common/config.ts | 1 + settings/settings.html | 16 ++++++++++++++ settings/settings.ts | 42 +++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 10 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index eb6f5374..8c365eaa 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -798,6 +798,14 @@ "join_the_community_cta": { "message": "Join them now!", "description": "Call to action to join a community. Initially for beta testing but could be reused for other purposes such as the community forum in future." + }, + "ignore_case": { + "message": "Ignore case", + "description": "Enabling this setting will cause a case-insensitive comparison to be made (e.g. when looking for matching names and IDs of forms to fill in)" + }, + "ignore_case_explanation_finding_forms": { + "message": "For example, 'search' in any of the include or exclude lists will match with 'search', 'Search' and 'SEARCH'. Unless you have very unusual and complex requirements, it is best to leave this option enabled.", + "description": "Describes the ignore case setting when used for configuring the include and exclude lists for finding forms." } } diff --git a/common/ConfigManager.ts b/common/ConfigManager.ts index 25299360..1981a97e 100644 --- a/common/ConfigManager.ts +++ b/common/ConfigManager.ts @@ -359,6 +359,12 @@ export class ConfigManager { ) { derivedConfig.preventSaveNotification = node.config.preventSaveNotification; } + if ( + node.config.listMatchingCaseSensitive !== undefined && + derivedConfig.listMatchingCaseSensitive == null + ) { + derivedConfig.listMatchingCaseSensitive = node.config.listMatchingCaseSensitive; + } if (node.config.blackList !== undefined) { if (derivedConfig.blackList === undefined) { @@ -438,16 +444,31 @@ export class ConfigManager { } public isFormInteresting(form: HTMLFormElement, conf: SiteConfig, otherFields: Field[]) { - const fieldIds = otherFields.map(field => field.locators[0].id); - const fieldNames = otherFields.map(field => field.locators[0].name); - const excludeFormIds = conf?.blackList?.form?.ids || []; - const excludeFormNames = conf?.blackList?.form?.names || []; - const excludeFieldIds = conf?.blackList?.fields?.ids || []; - const excludeFieldNames = conf?.blackList?.fields?.names || []; + const ic = conf.listMatchingCaseSensitive !== true; + const fieldIds = otherFields + .map(field => (ic ? field.locators[0]?.id.toLowerCase() : field.locators[0]?.id)) + .filter(Boolean); + const fieldNames = otherFields + .map(field => (ic ? field.locators[0]?.name.toLowerCase() : field.locators[0]?.name)) + .filter(Boolean); + const formId = ic ? form.id?.toLowerCase() : form.id; + const formName = ic ? form.name?.toLowerCase() : form.name; + const excludeFormIds = (conf?.blackList?.form?.ids || []) + .map(x => (ic ? x?.toLowerCase() : x)) + .filter(Boolean); + const excludeFormNames = (conf?.blackList?.form?.names || []) + .map(x => (ic ? x?.toLowerCase() : x)) + .filter(Boolean); + const excludeFieldIds = (conf?.blackList?.fields?.ids || []) + .map(x => (ic ? x?.toLowerCase() : x)) + .filter(Boolean); + const excludeFieldNames = (conf?.blackList?.fields?.names || []) + .map(x => (ic ? x?.toLowerCase() : x)) + .filter(Boolean); const excluded = - excludeFormIds.indexOf(form.id) >= 0 || - excludeFormNames.indexOf(form.name) >= 0 || + excludeFormIds.indexOf(formId) >= 0 || + excludeFormNames.indexOf(formName) >= 0 || excludeFieldIds.some(id => fieldIds.find(i => id === i) !== undefined) || excludeFieldNames.some(name => fieldNames.find(n => name === n) !== undefined); @@ -459,8 +480,8 @@ export class ConfigManager { const includeFieldNames = conf?.whiteList?.fields?.names || []; const included = - includeFormIds.indexOf(form.id) >= 0 || - includeFormNames.indexOf(form.name) >= 0 || + includeFormIds.indexOf(formId) >= 0 || + includeFormNames.indexOf(formName) >= 0 || includeFieldIds.some(id => fieldIds.find(i => id === i) !== undefined) || includeFieldNames.some(name => fieldNames.find(n => name === n) !== undefined); diff --git a/common/DefaultSiteConfig.ts b/common/DefaultSiteConfig.ts index ac9f1a97..8b01f1e8 100644 --- a/common/DefaultSiteConfig.ts +++ b/common/DefaultSiteConfig.ts @@ -19,6 +19,7 @@ defaultSiteConfig.pageRegex["^.*$"] = { */ preventSaveNotification: false, + listMatchingCaseSensitive: false, /* Forms will be scanned iff they have a password (type) field diff --git a/common/config.ts b/common/config.ts index f15dce98..57be7123 100644 --- a/common/config.ts +++ b/common/config.ts @@ -18,6 +18,7 @@ export class SiteConfig { whiteList?: FormMatchConfig; blackList?: FormMatchConfig; preventSaveNotification?: boolean; + listMatchingCaseSensitive?: boolean; } export class SiteConfigNode { diff --git a/settings/settings.html b/settings/settings.html index 061d41ae..6e20065b 100644 --- a/settings/settings.html +++ b/settings/settings.html @@ -249,6 +249,22 @@

+
+ +
+
+
+
+ +
+
+
+
+
diff --git a/settings/settings.ts b/settings/settings.ts index a473c6f9..2eae0977 100644 --- a/settings/settings.ts +++ b/settings/settings.ts @@ -125,6 +125,14 @@ function setupInputListeners() { document .getElementById("requestPasswordSaveSelect") .addEventListener("change", saveOfferToSavePasswords); + + document + .getElementById("pref_listMatchingIgnoreCase_label") + .addEventListener("change", saveListMatchingIgnoreCase); + document + .getElementById("listMatchingIgnoreCaseSelect") + .addEventListener("change", saveListMatchingIgnoreCase); + document.getElementById("pref_saveFavicons_label").addEventListener("change", saveSaveFavicons); document .getElementById("pref_rememberMRUGroup_label") @@ -557,6 +565,8 @@ function setSiteSpecificConfigValues() { (document.getElementById( "pref_notifyBarRequestPasswordSave_label" ) as HTMLInputElement).checked = siteConfig.preventSaveNotification === true ? null : true; + (document.getElementById("pref_listMatchingIgnoreCase_label") as HTMLInputElement).checked = + siteConfig.listMatchingCaseSensitive === true ? null : true; } else { const save: string = siteConfig.preventSaveNotification === true @@ -565,6 +575,15 @@ function setSiteSpecificConfigValues() { ? "Yes" : "Inherit"; (document.getElementById("requestPasswordSaveSelect") as HTMLSelectElement).value = save; + const ignoreCase: string = + siteConfig.listMatchingCaseSensitive === true + ? "No" + : siteConfig.listMatchingCaseSensitive === false + ? "Yes" + : "Inherit"; + (document.getElementById( + "listMatchingIgnoreCaseSelect" + ) as HTMLSelectElement).value = ignoreCase; } let enabled: boolean; @@ -965,6 +984,29 @@ function saveOfferToSavePasswords(e) { configManager.save(); } +function saveListMatchingIgnoreCase(e) { + e.preventDefault(); + + if (siteModeAll) { + const ignoreCase = (document.getElementById( + "pref_listMatchingIgnoreCase_label" + ) as HTMLInputElement).checked; + configManager.current.siteConfig.pageRegex[ + "^.*$" + ].config.listMatchingCaseSensitive = !ignoreCase; + } else { + const value = (document.getElementById("listMatchingIgnoreCaseSelect") as HTMLSelectElement) + .value; + const caseSensitive = value === "Inherit" ? null : value == "No" ? true : false; + const siteConfigLookup = configManager.siteConfigLookupFor( + specificSite.target, + specificSite.method + ); + siteConfigLookup[specificSite.value].config.listMatchingCaseSensitive = caseSensitive; + } + configManager.save(); +} + function saveSaveFavicons(e) { e.preventDefault(); configManager.setASAP({