Skip to content

Commit

Permalink
Including/excluding forms by string matching now ignores case
Browse files Browse the repository at this point in the history
Fixes #237
  • Loading branch information
luckyrat committed Oct 7, 2020
1 parent 66e93ef commit 21efb9d
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
8 changes: 8 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

}
41 changes: 31 additions & 10 deletions common/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions common/DefaultSiteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defaultSiteConfig.pageRegex["^.*$"] = {
*/

preventSaveNotification: false,
listMatchingCaseSensitive: false,

/*
Forms will be scanned iff they have a password (type) field
Expand Down
1 change: 1 addition & 0 deletions common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SiteConfig {
whiteList?: FormMatchConfig;
blackList?: FormMatchConfig;
preventSaveNotification?: boolean;
listMatchingCaseSensitive?: boolean;
}

export class SiteConfigNode {
Expand Down
16 changes: 16 additions & 0 deletions settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ <h3 class="panel-title" data-i18n="pref_Finding_forms_heading"></h3>
</div>
</div>
</fieldset>
<div class="checkbox">
<label class="nonSiteSpecificField"><input type="checkbox" id="pref_listMatchingIgnoreCase_label"><span data-i18n="ignore_case"></span></label>
<div class="form-horizontal siteSpecificToggle">
<div class="form-group formSettingGroup">
<div class="formSettingLabel"><span data-i18n="ignore_case"></span></div>
<div class="formSettingDropdown">
<select class="form-control" id="listMatchingIgnoreCaseSelect">
<option value="Yes" data-i18n="yes"></option>
<option value="No" data-i18n="no"></option>
<option value="Inherit" data-i18n="site_specific_settings_inherit"></option>
</select>
</div>
</div>
</div>
</div>
<div data-i18n="ignore_case_explanation_finding_forms"></div>
</div>
</div>

Expand Down
42 changes: 42 additions & 0 deletions settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 21efb9d

Please sign in to comment.