From 256be394deb494cb7ed3f5aa7bd20c4051ee5c1e Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 24 Aug 2024 11:42:32 +0300 Subject: [PATCH] Fix nodeName check --- keepassxc-browser/common/sites.js | 4 ++-- keepassxc-browser/content/fields.js | 6 +++--- keepassxc-browser/content/fill.js | 2 +- keepassxc-browser/content/form.js | 12 ++++++------ keepassxc-browser/content/keepassxc-browser.js | 2 +- keepassxc-browser/content/observer-helper.js | 6 +++--- keepassxc-browser/content/ui.js | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/keepassxc-browser/common/sites.js b/keepassxc-browser/common/sites.js index d27b9cf..2a65fa0 100644 --- a/keepassxc-browser/common/sites.js +++ b/keepassxc-browser/common/sites.js @@ -102,7 +102,7 @@ kpxcSites.exceptionFound = function(identifier, field) { * @returns {boolean} True if an Element has a match with the needed indentfifiers and document location */ kpxcSites.totpExceptionFound = function(field) { - if (!field || !matchesWithNodeName(field.nodeName, 'INPUT')) { + if (!field || !matchesWithNodeName(field, 'INPUT')) { return false; } @@ -121,7 +121,7 @@ kpxcSites.totpExceptionFound = function(field) { * @returns {boolean} True if an Element has a match with the needed indentfifiers and document location */ kpxcSites.segmentedTotpExceptionFound = function(form) { - if (!form || !matchesWithNodeName(form.nodeName, 'FORM')) { + if (!form || !matchesWithNodeName(form, 'FORM')) { return false; } diff --git a/keepassxc-browser/content/fields.js b/keepassxc-browser/content/fields.js index 7c2fcfb..54241a4 100644 --- a/keepassxc-browser/content/fields.js +++ b/keepassxc-browser/content/fields.js @@ -115,7 +115,7 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) { const addTotpFieldsToCombination = function(inputFields, ignoreFieldCount = false) { const totpInputs = Array.from(inputFields).filter( (e) => - matchesWithNodeName(e.nodeName, 'INPUT') && + matchesWithNodeName(e, 'INPUT') && e.type !== 'password' && e.type !== 'hidden' && e.type !== 'submit' @@ -155,8 +155,8 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) { // 7 inputs with a button as the last one (e.g. PayPal uses this) if ( currentForm.length === 7 && - (matchesWithNodeName(currentForm.lastChild.nodeName, 'BUTTON') || - (matchesWithNodeName(currentForm.lastChild.nodeName, 'INPUT') && + (matchesWithNodeName(currentForm.lastChild, 'BUTTON') || + (matchesWithNodeName(currentForm.lastChild, 'INPUT') && currentForm.lastChild.type === 'button')) ) { return true; diff --git a/keepassxc-browser/content/fill.js b/keepassxc-browser/content/fill.js index 33387c1..7bfe8d8 100644 --- a/keepassxc-browser/content/fill.js +++ b/keepassxc-browser/content/fill.js @@ -246,7 +246,7 @@ kpxcFill.fillInCredentials = async function(combination, predefinedUsername, uui } // Fill password - if (combination.password && matchesWithNodeName(combination.password.nodeName, 'INPUT')) { + if (combination.password && matchesWithNodeName(combination.password, 'INPUT')) { // Show a notification if password length exceeds the length defined in input if (combination.password.maxLength && combination.password.maxLength > 0 diff --git a/keepassxc-browser/content/form.js b/keepassxc-browser/content/form.js index 29b57c7..e9157e8 100644 --- a/keepassxc-browser/content/form.js +++ b/keepassxc-browser/content/form.js @@ -58,8 +58,8 @@ kpxcForm.getFormSubmitButton = function(form) { // Try to find similar buttons outside the form which are added via 'form' property for (const e of form.elements) { - if ((matchesWithNodeName(e.nodeName, 'BUTTON') && (e.type === 'button' || e.type === 'submit' || e.type === '')) - || (matchesWithNodeName(e.nodeName, 'INPUT') && (e.type === 'button' || e.type === 'submit'))) { + if ((matchesWithNodeName(e, 'BUTTON') && (e.type === 'button' || e.type === 'submit' || e.type === '')) + || (matchesWithNodeName(e, 'INPUT') && (e.type === 'button' || e.type === 'submit'))) { return e; } } @@ -127,13 +127,13 @@ kpxcForm.onSubmit = async function(e) { kpxcForm.submitTriggered = true; const searchForm = f => { - if (matchesWithNodeName(f.nodeName, 'FORM')) { + if (matchesWithNodeName(f, 'FORM')) { return f; } }; // Traverse parents if the form is not found. - let form = matchesWithNodeName(this.nodeName, 'FORM') + let form = matchesWithNodeName(this, 'FORM') ? this : kpxcFields.traverseParents(this, searchForm, searchForm, () => null); @@ -207,10 +207,10 @@ kpxcForm.saveForm = function(form, combination) { password: combination.password, totp: combination.totp, totpInputs: Array.from(form.elements).filter( - e => matchesWithNodeName(e.nodeName, 'INPUT') && kpxcTOTPIcons.isValid(e), + e => matchesWithNodeName(e, 'INPUT') && kpxcTOTPIcons.isValid(e), ), passwordInputs: Array.from(form.elements).filter( - e => matchesWithNodeName(e.nodeName, 'INPUT') && e.type === 'password', + e => matchesWithNodeName(e, 'INPUT') && e.type === 'password', ) }); }; diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 307834b..35b2a1a 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -600,7 +600,7 @@ kpxc.rememberCredentialsFromContextMenu = async function() { } const el = document.activeElement; - if (!matchesWithNodeName(el.nodeName, 'INPUT')) { + if (!matchesWithNodeName(el, 'INPUT')) { return; } diff --git a/keepassxc-browser/content/observer-helper.js b/keepassxc-browser/content/observer-helper.js index 2f76a95..6e1a1c5 100644 --- a/keepassxc-browser/content/observer-helper.js +++ b/keepassxc-browser/content/observer-helper.js @@ -73,7 +73,7 @@ kpxcObserverHelper.initObserver = async function() { } } else if (mut.type === 'attributes' && (mut.attributeName === 'class' || mut.attributeName === 'style')) { // Only accept targets with forms - const forms = matchesWithNodeName(mut.target.nodeName, 'FORM') ? mut.target : mut.target.getElementsByTagName('form'); + const forms = matchesWithNodeName(mut.target, 'FORM') ? mut.target : mut.target.getElementsByTagName('form'); if (forms.length === 0 && !kpxcSites.exceptionFound(mut.target.classList, mut.target)) { continue; } @@ -146,7 +146,7 @@ kpxcObserverHelper.getInputs = function(target, ignoreVisibility = false) { } }); - if (matchesWithNodeName(target.nodeName, 'INPUT')) { + if (matchesWithNodeName(target, 'INPUT')) { inputFields.push(target); } @@ -304,7 +304,7 @@ const traverseChildren = function(target, inputFields, depth = 1) { continue; } - if (matchesWithNodeName(child.nodeName, 'INPUT')) { + if (matchesWithNodeName(child, 'INPUT')) { inputFields.push(child); } diff --git a/keepassxc-browser/content/ui.js b/keepassxc-browser/content/ui.js index 5f70b4e..aae3929 100644 --- a/keepassxc-browser/content/ui.js +++ b/keepassxc-browser/content/ui.js @@ -133,7 +133,7 @@ kpxcUI.monitorIconPosition = function(iconClass) { }); window.addEventListener('transitionend', function(e) { - if (matchesWithNodeName(e.target?.nodeName, 'INPUT') || matchesWithNodeName(e.target?.nodeName, 'TEXTAREA')) { + if (matchesWithNodeName(e.target, 'INPUT') || matchesWithNodeName(e.target, 'TEXTAREA')) { kpxcUI.updateIconPosition(iconClass); } });