Merge pull request #2324 from keepassxreboot/fix/nodename_check

Fix nodeName check
This commit is contained in:
Sami Vänttinen 2024-08-24 14:16:30 +03:00 committed by GitHub
commit 17a5fa5f45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 17 deletions

View file

@ -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 * @returns {boolean} True if an Element has a match with the needed indentfifiers and document location
*/ */
kpxcSites.totpExceptionFound = function(field) { kpxcSites.totpExceptionFound = function(field) {
if (!field || !matchesWithNodeName(field.nodeName, 'INPUT')) { if (!field || !matchesWithNodeName(field, 'INPUT')) {
return false; 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 * @returns {boolean} True if an Element has a match with the needed indentfifiers and document location
*/ */
kpxcSites.segmentedTotpExceptionFound = function(form) { kpxcSites.segmentedTotpExceptionFound = function(form) {
if (!form || !matchesWithNodeName(form.nodeName, 'FORM')) { if (!form || !matchesWithNodeName(form, 'FORM')) {
return false; return false;
} }

View file

@ -115,7 +115,7 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
const addTotpFieldsToCombination = function(inputFields, ignoreFieldCount = false) { const addTotpFieldsToCombination = function(inputFields, ignoreFieldCount = false) {
const totpInputs = Array.from(inputFields).filter( const totpInputs = Array.from(inputFields).filter(
(e) => (e) =>
matchesWithNodeName(e.nodeName, 'INPUT') && matchesWithNodeName(e, 'INPUT') &&
e.type !== 'password' && e.type !== 'password' &&
e.type !== 'hidden' && e.type !== 'hidden' &&
e.type !== 'submit' 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) // 7 inputs with a button as the last one (e.g. PayPal uses this)
if ( if (
currentForm.length === 7 && currentForm.length === 7 &&
(matchesWithNodeName(currentForm.lastChild.nodeName, 'BUTTON') || (matchesWithNodeName(currentForm.lastChild, 'BUTTON') ||
(matchesWithNodeName(currentForm.lastChild.nodeName, 'INPUT') && (matchesWithNodeName(currentForm.lastChild, 'INPUT') &&
currentForm.lastChild.type === 'button')) currentForm.lastChild.type === 'button'))
) { ) {
return true; return true;

View file

@ -246,7 +246,7 @@ kpxcFill.fillInCredentials = async function(combination, predefinedUsername, uui
} }
// Fill password // 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 // Show a notification if password length exceeds the length defined in input
if (combination.password.maxLength if (combination.password.maxLength
&& combination.password.maxLength > 0 && combination.password.maxLength > 0

View file

@ -58,8 +58,8 @@ kpxcForm.getFormSubmitButton = function(form) {
// Try to find similar buttons outside the form which are added via 'form' property // Try to find similar buttons outside the form which are added via 'form' property
for (const e of form.elements) { for (const e of form.elements) {
if ((matchesWithNodeName(e.nodeName, 'BUTTON') && (e.type === 'button' || e.type === 'submit' || e.type === '')) if ((matchesWithNodeName(e, 'BUTTON') && (e.type === 'button' || e.type === 'submit' || e.type === ''))
|| (matchesWithNodeName(e.nodeName, 'INPUT') && (e.type === 'button' || e.type === 'submit'))) { || (matchesWithNodeName(e, 'INPUT') && (e.type === 'button' || e.type === 'submit'))) {
return e; return e;
} }
} }
@ -127,13 +127,13 @@ kpxcForm.onSubmit = async function(e) {
kpxcForm.submitTriggered = true; kpxcForm.submitTriggered = true;
const searchForm = f => { const searchForm = f => {
if (matchesWithNodeName(f.nodeName, 'FORM')) { if (matchesWithNodeName(f, 'FORM')) {
return f; return f;
} }
}; };
// Traverse parents if the form is not found. // Traverse parents if the form is not found.
let form = matchesWithNodeName(this.nodeName, 'FORM') let form = matchesWithNodeName(this, 'FORM')
? this ? this
: kpxcFields.traverseParents(this, searchForm, searchForm, () => null); : kpxcFields.traverseParents(this, searchForm, searchForm, () => null);
@ -207,10 +207,10 @@ kpxcForm.saveForm = function(form, combination) {
password: combination.password, password: combination.password,
totp: combination.totp, totp: combination.totp,
totpInputs: Array.from(form.elements).filter( 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( passwordInputs: Array.from(form.elements).filter(
e => matchesWithNodeName(e.nodeName, 'INPUT') && e.type === 'password', e => matchesWithNodeName(e, 'INPUT') && e.type === 'password',
) )
}); });
}; };

View file

@ -600,7 +600,7 @@ kpxc.rememberCredentialsFromContextMenu = async function() {
} }
const el = document.activeElement; const el = document.activeElement;
if (!matchesWithNodeName(el.nodeName, 'INPUT')) { if (!matchesWithNodeName(el, 'INPUT')) {
return; return;
} }

View file

@ -73,7 +73,7 @@ kpxcObserverHelper.initObserver = async function() {
} }
} else if (mut.type === 'attributes' && (mut.attributeName === 'class' || mut.attributeName === 'style')) { } else if (mut.type === 'attributes' && (mut.attributeName === 'class' || mut.attributeName === 'style')) {
// Only accept targets with forms // 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)) { if (forms.length === 0 && !kpxcSites.exceptionFound(mut.target.classList, mut.target)) {
continue; continue;
} }
@ -146,7 +146,7 @@ kpxcObserverHelper.getInputs = function(target, ignoreVisibility = false) {
} }
}); });
if (matchesWithNodeName(target.nodeName, 'INPUT')) { if (matchesWithNodeName(target, 'INPUT')) {
inputFields.push(target); inputFields.push(target);
} }
@ -304,7 +304,7 @@ const traverseChildren = function(target, inputFields, depth = 1) {
continue; continue;
} }
if (matchesWithNodeName(child.nodeName, 'INPUT')) { if (matchesWithNodeName(child, 'INPUT')) {
inputFields.push(child); inputFields.push(child);
} }

View file

@ -133,7 +133,7 @@ kpxcUI.monitorIconPosition = function(iconClass) {
}); });
window.addEventListener('transitionend', function(e) { 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); kpxcUI.updateIconPosition(iconClass);
} }
}); });