From 9dc05a7e52f87d89ce4f24ae0d35ac819886f3af Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 17 Jan 2026 09:09:21 +0200 Subject: [PATCH] Fix main URL validation when using placeholders --- src/gui/URLEdit.cpp | 18 ++++++++++++------ src/gui/URLEdit.h | 8 ++++++-- src/gui/entry/EditEntryWidget.cpp | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/gui/URLEdit.cpp b/src/gui/URLEdit.cpp index fed277f00..2d13501ea 100644 --- a/src/gui/URLEdit.cpp +++ b/src/gui/URLEdit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2014 Felix Geyer * * 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 { diff --git a/src/gui/URLEdit.h b/src/gui/URLEdit.h index a852f2664..635ea1a41 100644 --- a/src/gui/URLEdit.h +++ b/src/gui/URLEdit.h @@ -1,6 +1,6 @@ /* + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2014 Felix Geyer - * Copyright (C) 2019 KeePassXC Team * * 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 #include +#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 m_errorAction; + QPointer m_entry; }; #endif // KEEPASSX_URLEDIT_H diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 816899374..2a1dde612 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 KeePassXC Team + * Copyright (C) 2026 KeePassXC Team * Copyright (C) 2010 Felix Geyer * * 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());