From e5904135449db1eadeb806fb334cedff0e089744 Mon Sep 17 00:00:00 2001 From: Eric Lemesre Date: Sun, 9 Aug 2026 04:48:36 +0200 Subject: [PATCH] Fix history items losing entry CustomData (#13573) * Fix history items losing entry CustomData Entry::beginUpdate() copied attributes, attachments and auto-type associations into the temporary history item but not CustomData, unlike clone() and copyDataFrom(). As a result every history item was created with empty CustomData, and restoring an entry from history wiped its CustomData, losing KeePassXC-Browser settings and other client metadata. Copy CustomData into the history item like the other components and add TestEntry::testHistoryItemCustomData covering creation and restore. Co-Authored-By: Claude Fable 5 * Removed redundant code to ensure consistency --------- Co-authored-by: Claude Fable 5 Co-authored-by: Jonathan White --- src/core/Entry.cpp | 13 ++++--------- tests/TestEntry.cpp | 24 ++++++++++++++++++++++++ tests/TestEntry.h | 1 + 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 34c96d0d5..ba2fa934c 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -1039,10 +1039,8 @@ Entry* Entry::clone(CloneFlags flags) const } else { entry->m_uuid = m_uuid; } - entry->m_data = m_data; - entry->m_customData->copyDataFrom(m_customData); - entry->m_attributes->copyDataFrom(m_attributes); - entry->m_attachments->copyDataFrom(m_attachments); + entry->copyDataFrom(this); + entry->setUpdateTimeinfo(false); if (flags & CloneUserAsRef) { entry->m_attributes->set(EntryAttributes::UserNameKey, @@ -1101,12 +1099,9 @@ void Entry::beginUpdate() Q_ASSERT(m_tmpHistoryItem.isNull()); m_tmpHistoryItem.reset(new Entry()); - m_tmpHistoryItem->setUpdateTimeinfo(false); m_tmpHistoryItem->m_uuid = m_uuid; - m_tmpHistoryItem->m_data = m_data; - m_tmpHistoryItem->m_attributes->copyDataFrom(m_attributes); - m_tmpHistoryItem->m_attachments->copyDataFrom(m_attachments); - m_tmpHistoryItem->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations); + m_tmpHistoryItem->copyDataFrom(this); + m_tmpHistoryItem->setUpdateTimeinfo(false); m_modifiedSinceBegin = false; } diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index bd729dc8d..f7ea9fc5f 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -48,6 +48,30 @@ void TestEntry::testHistoryItemDeletion() QVERIFY(historyEntry.isNull()); } +void TestEntry::testHistoryItemCustomData() +{ + QScopedPointer entry(new Entry()); + entry->setUuid(QUuid::createUuid()); + entry->setTitle("Original Title"); + entry->customData()->set("CustomKey", "CustomValue"); + + entry->beginUpdate(); + entry->setTitle("New Title"); + entry->endUpdate(); + + // The history item must carry the custom data present before the update + QCOMPARE(entry->historyItems().size(), 1); + const Entry* historyItem = entry->historyItems().constFirst(); + QCOMPARE(historyItem->customData()->value("CustomKey"), QString("CustomValue")); + + // Restoring from the history item restores the custom data + entry->customData()->remove("CustomKey"); + QVERIFY(entry->customData()->isEmpty()); + + entry->copyDataFrom(historyItem); + QCOMPARE(entry->customData()->value("CustomKey"), QString("CustomValue")); +} + void TestEntry::testCopyDataFrom() { QScopedPointer entry(new Entry()); diff --git a/tests/TestEntry.h b/tests/TestEntry.h index 953a7ce7b..e71753605 100644 --- a/tests/TestEntry.h +++ b/tests/TestEntry.h @@ -29,6 +29,7 @@ class TestEntry : public QObject private slots: void initTestCase(); void testHistoryItemDeletion(); + void testHistoryItemCustomData(); void testCopyDataFrom(); void testClone(); void testResolveUrl();