Merge pull request #1976 from keepassxreboot/fix/get_combination_from_custom_login_fields

Fix getting combination from Custom Login Fields during credential save
This commit is contained in:
Sami Vänttinen 2023-09-01 07:11:26 +03:00 committed by GitHub
commit 982c251cf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -195,10 +195,9 @@ kpxcFields.getAllPageInputs = async function(previousInputs = []) {
/**
* Returns the combination where input field is used
* @param {HTMLElement} field Input field
* @param {String} givenType 'username' or 'password'
* @param {String} givenType For example: 'username', 'password', 'totp', 'totpInputs'
*/
kpxcFields.getCombination = async function(field, givenType) {
// If givenType is not set, return the combination that uses the selected field
for (const combination of kpxc.combinations) {
if (givenType) {
// Strictly search a given type

View file

@ -546,22 +546,27 @@ kpxc.rememberCredentials = async function(usernameValue, passwordValue, urlValue
// Save credentials triggered fron the context menu
kpxc.rememberCredentialsFromContextMenu = async function() {
if (kpxc.databaseState === DatabaseState.LOCKED) {
kpxcUI.createNotification('error', tr('rememberErrorDatabaseClosed'));
return;
}
const el = document.activeElement;
if (el.nodeName !== 'INPUT') {
return;
}
const type = el.getAttribute('type');
const combination = await kpxcFields.getCombination(el, (type === 'password' ? type : 'username'));
const combination = await kpxcFields.getCombination(el);
if (!combination) {
logDebug('Error: No combination found.');
return;
}
const usernameValue = combination.username ? combination.username.value : '';
const passwordValue = combination.password ? combination.password.value : '';
const usernameValue = combination.username?.value ?? '';
const passwordValue = combination.password?.value ?? '';
const result = await kpxc.rememberCredentials(usernameValue, passwordValue, undefined, undefined, kpxc.settings.showLoginNotifications);
const result = await kpxc.rememberCredentials(usernameValue, passwordValue, undefined, undefined,
kpxc.settings.showLoginNotifications);
if (result === undefined) {
kpxcUI.createNotification('error', tr('rememberNoPassword'));
return;