diff options
author | Jonathan White <support@dmapps.us> | 2021-03-24 06:42:31 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2021-05-30 15:44:09 +0300 |
commit | 5be06190bb1afddcc8840616217ff46a0efaa3c9 (patch) | |
tree | e3db8a6470e0e00fe9fdc2d8800c433ef59b9e4b | |
parent | b47272a5ce1ef391d881f8e5168afe0a8a96a6d6 (diff) |
OPVault: Use Text instead of Name for attribute and section names
* Fix #6303 - the text attribute in 1Password contains the actual text seen in 1Password whereas the name attribute may contain a ref pointer and not a name.
-rw-r--r-- | src/format/OpVaultReader.h | 2 | ||||
-rw-r--r-- | src/format/OpVaultReaderSections.cpp | 21 | ||||
-rw-r--r-- | tests/TestOpVaultReader.cpp | 8 |
3 files changed, 12 insertions, 19 deletions
diff --git a/src/format/OpVaultReader.h b/src/format/OpVaultReader.h index 585415854..846e65dd3 100644 --- a/src/format/OpVaultReader.h +++ b/src/format/OpVaultReader.h @@ -98,7 +98,7 @@ private: bool fillAttributes(Entry* entry, const QJsonObject& bandEntry); void fillFromSection(Entry* entry, const QJsonObject& section); - void fillFromSectionField(Entry* entry, const QString& sectionName, QJsonObject& field); + void fillFromSectionField(Entry* entry, const QString& sectionName, const QJsonObject& field); QString resolveAttributeName(const QString& section, const QString& name, const QString& text); void populateCategoryGroups(Group* rootGroup); diff --git a/src/format/OpVaultReaderSections.cpp b/src/format/OpVaultReaderSections.cpp index e59dd9f02..b7677ec05 100644 --- a/src/format/OpVaultReaderSections.cpp +++ b/src/format/OpVaultReaderSections.cpp @@ -53,12 +53,11 @@ namespace void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section) { const auto uuid = entry->uuid(); - QString sectionName = section["name"].toString(); + auto sectionTitle = section["title"].toString(); if (!section.contains("fields")) { - auto sectionNameLC = sectionName.toLower(); - auto sectionTitleLC = section["title"].toString("").toLower(); - if (!(sectionNameLC == "linked items" && sectionTitleLC == "related items")) { + auto sectionName = section["name"].toString(); + if (!(sectionName.toLower() == "linked items" && sectionTitle.toLower() == "related items")) { qWarning() << R"(Skipping "fields"-less Section in UUID ")" << uuid << "\": <<" << section << ">>"; } return; @@ -67,23 +66,17 @@ void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section) return; } - // If we have a default section name then replace with the section title if not empty - if (sectionName.startsWith("Section_") && !section["title"].toString().isEmpty()) { - sectionName = section["title"].toString(); - } - QJsonArray sectionFields = section["fields"].toArray(); for (const QJsonValue sectionField : sectionFields) { if (!sectionField.isObject()) { qWarning() << R"(Skipping non-Object "fields" in UUID ")" << uuid << "\": << " << sectionField << ">>"; continue; } - QJsonObject field = sectionField.toObject(); - fillFromSectionField(entry, sectionName, field); + fillFromSectionField(entry, sectionTitle, sectionField.toObject()); } } -void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionName, QJsonObject& field) +void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionName, const QJsonObject& field) { if (!field.contains("v")) { // for our purposes, we don't care if there isn't a value in the field @@ -161,8 +154,8 @@ QString OpVaultReader::resolveAttributeName(const QString& section, const QStrin || lowName == "website") { return EntryAttributes::URLKey; } - return name; + return text; } - return QString("%1_%2").arg(section, name); + return QString("%1_%2").arg(section, text); } diff --git a/tests/TestOpVaultReader.cpp b/tests/TestOpVaultReader.cpp index 94b5c35f0..dc5c04e3f 100644 --- a/tests/TestOpVaultReader.cpp +++ b/tests/TestOpVaultReader.cpp @@ -97,10 +97,10 @@ void TestOpVaultReader::testReadIntoDatabase() entry = db->rootGroup()->findEntryByPath("/Credit Card/My Credit Card"); QVERIFY(entry); auto attr = entry->attributes(); - QCOMPARE(attr->value("cardholder"), QStringLiteral("Team KeePassXC")); - QVERIFY(!attr->value("validFrom").isEmpty()); - QCOMPARE(attr->value("details_pin"), QStringLiteral("1234")); - QVERIFY(attr->isProtected("details_pin")); + QCOMPARE(attr->value("cardholder name"), QStringLiteral("Team KeePassXC")); + QVERIFY(!attr->value("valid from").isEmpty()); + QCOMPARE(attr->value("Additional Details_PIN"), QStringLiteral("1234")); + QVERIFY(attr->isProtected("Additional Details_PIN")); // Confirm address fields entry = db->rootGroup()->findEntryByPath("/Identity/Team KeePassXC"); |