mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-27 18:10:31 -05:00
Implement {UUID} placeholder and nested reference support (#12511)
* Closes #12509 * Implement the {UUID} placeholder * Implement nested placeholder de-referencing when resolving entry references to support a reference like {REF:U@I:{UUID}} which is equivalent to {USERNAME} placeholder. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: droidmonkey <2809491+droidmonkey@users.noreply.github.com> Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
parent
fd2a729677
commit
5736c6379c
5 changed files with 54 additions and 2 deletions
|
|
@ -445,6 +445,49 @@ void TestEntry::testResolveReferencePlaceholders()
|
|||
entry3->attributes()->value("AttributeNotes"));
|
||||
}
|
||||
|
||||
void TestEntry::testResolveUuidPlaceholder()
|
||||
{
|
||||
Database db;
|
||||
auto* root = db.rootGroup();
|
||||
|
||||
auto* entry = new Entry();
|
||||
entry->setGroup(root);
|
||||
entry->setUuid(QUuid::createUuid());
|
||||
entry->setTitle("Test Entry");
|
||||
entry->setUsername("TestUser");
|
||||
entry->setPassword("TestPass");
|
||||
entry->setNotes("Test with UUID: {UUID}");
|
||||
|
||||
// Test that {UUID} placeholder resolves to the entry's UUID
|
||||
QString expectedUuid = entry->uuidToHex();
|
||||
QString resolvedNotes = entry->resolveMultiplePlaceholders(entry->notes());
|
||||
QCOMPARE(resolvedNotes, QString("Test with UUID: %1").arg(expectedUuid));
|
||||
|
||||
// Test {UUID} placeholder directly
|
||||
QCOMPARE(entry->resolveMultiplePlaceholders("{UUID}"), expectedUuid);
|
||||
|
||||
// Test case insensitivity
|
||||
QCOMPARE(entry->resolveMultiplePlaceholders("{uuid}"), expectedUuid);
|
||||
QCOMPARE(entry->resolveMultiplePlaceholders("{Uuid}"), expectedUuid);
|
||||
|
||||
// Test mixed case in text
|
||||
QCOMPARE(entry->resolveMultiplePlaceholders("UUID is {UUID} here"), QString("UUID is %1 here").arg(expectedUuid));
|
||||
|
||||
// Test advanced attribute with {REF:U@I:{UUID}} - should resolve to the entry's own username
|
||||
entry->attributes()->set("SelfReference", "{REF:U@I:{UUID}}");
|
||||
QString attributeValue = entry->attributes()->value("SelfReference");
|
||||
QString resolvedSelfRef = entry->resolveMultiplePlaceholders(attributeValue);
|
||||
|
||||
// Test the manual reference to confirm it works as before
|
||||
QString manualReference = QString("{REF:U@I:%1}").arg(entry->uuidToHex());
|
||||
entry->attributes()->set("ManualReference", manualReference);
|
||||
QString resolvedManualRef = entry->resolveMultiplePlaceholders(entry->attributes()->value("ManualReference"));
|
||||
|
||||
// Test that both approaches work
|
||||
QCOMPARE(resolvedManualRef, entry->username());
|
||||
QCOMPARE(resolvedSelfRef, entry->username());
|
||||
}
|
||||
|
||||
void TestEntry::testResolveNonIdPlaceholdersToUuid()
|
||||
{
|
||||
Database db;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue