From d0016bf6c409e6315033462b2b25c3eedb3248c3 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 24 Jun 2012 18:22:18 +0200 Subject: [PATCH] Fix reading non-ASCII passwords that are protected. Closes #28 --- src/format/KeePass2XmlReader.cpp | 2 +- tests/TestKeePass2Writer.cpp | 6 ++++++ tests/TestKeePass2Writer.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/format/KeePass2XmlReader.cpp b/src/format/KeePass2XmlReader.cpp index 2132b7933..564f5394b 100644 --- a/src/format/KeePass2XmlReader.cpp +++ b/src/format/KeePass2XmlReader.cpp @@ -635,7 +635,7 @@ void KeePass2XmlReader::parseEntryString(Entry* entry) if (isProtected && !value.isEmpty()) { if (m_randomStream) { - value = m_randomStream->process(QByteArray::fromBase64(value.toAscii())); + value = QString::fromUtf8(m_randomStream->process(QByteArray::fromBase64(value.toAscii()))); } else { raiseError(9); diff --git a/tests/TestKeePass2Writer.cpp b/tests/TestKeePass2Writer.cpp index f2b40f94d..320996751 100644 --- a/tests/TestKeePass2Writer.cpp +++ b/tests/TestKeePass2Writer.cpp @@ -43,6 +43,7 @@ void TestKeePass2Writer::initTestCase() group->setUuid(Uuid::random()); group->setNotes("I'm a note!"); Entry* entry = new Entry(); + entry->setPassword(QString::fromUtf8("\xc3\xa4\xa3\xb6\xc3\xbc\xe9\x9b\xbb\xe7\xb4\x85")); entry->setUuid(Uuid::random()); entry->attributes()->set("test", "protectedTest", true); QVERIFY(entry->attributes()->isProtected("test")); @@ -93,6 +94,11 @@ void TestKeePass2Writer::testAttachments() QCOMPARE(entry->attachments()->value("aaa.txt"), QByteArray("also an attachment")); } +void TestKeePass2Writer::testNonAsciiPasswords() +{ + QCOMPARE(m_dbTest->rootGroup()->entries()[0]->password(), m_dbOrg->rootGroup()->entries()[0]->password()); +} + void TestKeePass2Writer::cleanupTestCase() { delete m_dbOrg; diff --git a/tests/TestKeePass2Writer.h b/tests/TestKeePass2Writer.h index dee68c290..f11403d22 100644 --- a/tests/TestKeePass2Writer.h +++ b/tests/TestKeePass2Writer.h @@ -31,6 +31,7 @@ private Q_SLOTS: void testBasic(); void testProtectedAttributes(); void testAttachments(); + void testNonAsciiPasswords(); void cleanupTestCase(); private: