diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index b8e58929..0e327dc4 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -633,7 +633,7 @@ Entry* Entry::clone(CloneFlags flags) const entry->m_attributes->set(EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey)); } - entry->m_autoTypeAssociations->copyDataFrom(this->m_autoTypeAssociations); + entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations); if (flags & CloneIncludeHistory) { for (Entry* historyItem : m_history) { Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid); @@ -679,6 +679,7 @@ void Entry::beginUpdate() 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_modifiedSinceBegin = false; } diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index 6d3e38bb..625cbd42 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -156,9 +156,13 @@ bool EntryAttachments::operator!=(const EntryAttachments& other) const int EntryAttachments::attachmentsSize(const QSet &ignoredAttachments) const { int size = 0; - const QSet consideredAttachments = m_attachments.values().toSet() - ignoredAttachments; - for (const QByteArray& attachment : consideredAttachments) { - size += attachment.size(); + + QMapIterator i(m_attachments); + while (i.hasNext()) { + i.next(); + if( ! ignoredAttachments.contains( i.value() )){ + size += i.key().toUtf8().size() + i.value().size(); + } } return size; } diff --git a/tests/TestEntry.cpp b/tests/TestEntry.cpp index 47082d12..598ad33f 100644 --- a/tests/TestEntry.cpp +++ b/tests/TestEntry.cpp @@ -20,7 +20,6 @@ #include -#include "core/Database.h" #include "core/Entry.h" #include "core/Group.h" #include "crypto/Crypto.h" @@ -48,6 +47,7 @@ void TestEntry::testHistoryItemDeletion() delete entry; } + void TestEntry::testCopyDataFrom() { Entry* entry = new Entry(); diff --git a/tests/TestModified.cpp b/tests/TestModified.cpp index 70a4a484..9ae28b80 100644 --- a/tests/TestModified.cpp +++ b/tests/TestModified.cpp @@ -465,5 +465,52 @@ void TestModified::testHistoryItem() entry3->endUpdate(); QCOMPARE(entry3->historyItems().size(), 2); + Entry* entry4 = new Entry(); + entry4->setGroup(root); + QCOMPARE(entry4->historyItems().size(), 0); + + int reservedSize = entry4->attributes()->attributesSize(); + entry4->beginUpdate(); + entry4->attachments()->set("test1", QByteArray(17000 - 5 - reservedSize + 1, 'a')); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 1); + + entry4->beginUpdate(); + entry4->attachments()->remove("test1"); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 0); + + entry4->beginUpdate(); + entry4->setTags(QByteArray(17000 - reservedSize + 1, 'a')); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 1); + + entry4->beginUpdate(); + entry4->setTags(""); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 0); + + entry4->beginUpdate(); + entry4->attributes()->set("test3", QByteArray(17000 - 5 - reservedSize + 1, 'a')); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 1); + + entry4->beginUpdate(); + entry4->attributes()->remove("test3"); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 0); + + entry4->beginUpdate(); + AutoTypeAssociations::Association association; + association.window = "test3"; + association.sequence = QByteArray(17000 - 5 - reservedSize + 1, 'a'); + entry4->autoTypeAssociations()->add(association); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 1); + + entry4->beginUpdate(); + entry4->autoTypeAssociations()->remove(0); + entry4->endUpdate(); + QCOMPARE(entry4->historyItems().size(), 0); delete db; }