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 <[email protected]>

* Removed redundant code to ensure consistency

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Co-authored-by: Jonathan White <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-08-08 22:48:36 -04:00
1 parent 0b0b2938eb
commit e590413544
3 files changed
+29 -9

No files matched your search

+4 -9
View File
@@ -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;
}
+24
View File
@@ -48,6 +48,30 @@ void TestEntry::testHistoryItemDeletion()
QVERIFY(historyEntry.isNull());
}
void TestEntry::testHistoryItemCustomData()
{
QScopedPointer<Entry> 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> entry(new Entry());
+1
View File
@@ -29,6 +29,7 @@ class TestEntry : public QObject
private slots:
void initTestCase();
void testHistoryItemDeletion();
void testHistoryItemCustomData();
void testCopyDataFrom();
void testClone();
void testResolveUrl();