Skip to content

Commit

Permalink
Fix attribute lookup when the key contains ':'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetf committed Mar 5, 2019
1 parent d3b8324 commit ce0bf35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/fdosecrets/objects/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace FdoSecrets
if (it.key() == EntryAttributes::PasswordKey) {
continue;
}
auto field = attrKeyToField.value(it.key(), QStringLiteral("_") + it.key());
auto field = attrKeyToField.value(it.key(), QStringLiteral("_") + Item::encodeAttributeKey(it.key()));
terms << QStringLiteral(R"raw(+%1:"%2")raw").arg(field, it.value());
}

Expand Down
18 changes: 16 additions & 2 deletions src/fdosecrets/objects/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ namespace FdoSecrets
// add custom attributes
const auto customKeys = entryAttrs->customKeys();
for (const auto& attr : customKeys) {
attrs[attr] = entryAttrs->value(attr);
// decode attr key
auto decoded = decodeAttributeKey(attr);

attrs[decoded] = entryAttrs->value(attr);
}

// add some informative and readonly attributes
Expand Down Expand Up @@ -131,7 +134,8 @@ namespace FdoSecrets
continue;
}

entryAttrs->set(it.key(), it.value());
auto encoded = encodeAttributeKey(it.key());
entryAttrs->set(encoded, it.value());
}

m_backend->endUpdate();
Expand Down Expand Up @@ -350,6 +354,16 @@ namespace FdoSecrets
return pathComponents.join('/');
}

QString Item::encodeAttributeKey(const QString &key)
{
return QUrl::toPercentEncoding(key, "", "_:").replace('%', '_');
}

QString Item::decodeAttributeKey(const QString &key)
{
return QString::fromUtf8(QByteArray::fromPercentEncoding(key.toLatin1(), '_'));
}

void setEntrySecret(Entry* entry, const QByteArray& data, const QString& contentType)
{
auto mimeName = contentType.split(';').takeFirst().trimmed();
Expand Down
10 changes: 10 additions & 0 deletions src/fdosecrets/objects/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ namespace FdoSecrets
public:
static const QSet<QString> ReadOnlyAttributes;

/**
* Due to the limitation in EntrySearcher, custom attr key cannot contain ':',
* Thus we encode the key when saving and decode it when returning.
* @param key
* @return
*/
static QString encodeAttributeKey(const QString& key);
static QString decodeAttributeKey(const QString& key);


DBusReturn<void> setProperties(const QVariantMap& properties);

Entry* backend() const;
Expand Down

0 comments on commit ce0bf35

Please sign in to comment.