Fix main URL validation when using placeholders

This commit is contained in:
varjolintu 2026-01-17 09:09:21 +02:00 committed by Jonathan White
parent e591e93d42
commit 9dc05a7e52
3 changed files with 20 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
@ -37,16 +37,22 @@ void URLEdit::enableVerifyMode()
{
updateStylesheet();
connect(this, SIGNAL(textChanged(QString)), SLOT(updateStylesheet()));
connect(this, SIGNAL(textChanged(QString)), SLOT(updateStylesheet(QString)));
}
void URLEdit::updateStylesheet()
void URLEdit::setEntry(Entry* entry)
{
m_entry = entry;
}
void URLEdit::updateStylesheet(const QString& url)
{
const QString stylesheetTemplate("QLineEdit { background: %1; }");
const auto resolvedUrl = m_entry ? m_entry->resolveMultiplePlaceholders(url) : url;
if (!urlTools()->isUrlValid(text())) {
StateColorPalette statePalette;
QColor color = statePalette.color(StateColorPalette::ColorRole::Error);
if (!urlTools()->isUrlValid(resolvedUrl)) {
const StateColorPalette statePalette;
const auto color = statePalette.color(StateColorPalette::ColorRole::Error);
setStyleSheet(stylesheetTemplate.arg(color.name()));
m_errorAction->setVisible(true);
} else {

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,6 +23,8 @@
#include <QLineEdit>
#include <QPointer>
#include "core/Entry.h"
class URLEdit : public QLineEdit
{
Q_OBJECT
@ -30,12 +32,14 @@ class URLEdit : public QLineEdit
public:
explicit URLEdit(QWidget* parent = nullptr);
void enableVerifyMode();
void setEntry(Entry* entry);
private slots:
void updateStylesheet();
void updateStylesheet(const QString& url = {});
private:
QPointer<QAction> m_errorAction;
QPointer<Entry> m_entry;
};
#endif // KEEPASSX_URLEDIT_H

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
@ -1006,6 +1006,7 @@ void EditEntryWidget::setForms(Entry* entry, bool restore)
m_autoTypeUi->windowSequenceEdit->setReadOnly(m_history);
m_historyWidget->setEnabled(!m_history);
m_mainUi->urlEdit->setEntry(entry);
m_mainUi->titleEdit->setText(entry->title());
m_mainUi->usernameComboBox->lineEdit()->setText(entry->username());
m_mainUi->urlEdit->setText(entry->url());