mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-30 09:46:30 -05:00
Merge pull request #405 from keepassxreboot/fix/copyURL
Fix regex for placeholders and add regression test
This commit is contained in:
commit
a045594b57
@ -649,7 +649,8 @@ const Database* Entry::database() const
|
|||||||
QString Entry::resolveMultiplePlaceholders(const QString& str) const
|
QString Entry::resolveMultiplePlaceholders(const QString& str) const
|
||||||
{
|
{
|
||||||
QString result = str;
|
QString result = str;
|
||||||
QRegExp tmplRegEx("({.*})", Qt::CaseInsensitive, QRegExp::RegExp2);
|
QRegExp tmplRegEx("(\\{.*\\})", Qt::CaseInsensitive, QRegExp::RegExp2);
|
||||||
|
tmplRegEx.setMinimal(true);
|
||||||
QStringList tmplList;
|
QStringList tmplList;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ void DatabaseWidget::copyTitle()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->resolvePlaceholder(currentEntry->title()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->title()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::copyUsername()
|
void DatabaseWidget::copyUsername()
|
||||||
@ -418,7 +418,7 @@ void DatabaseWidget::copyUsername()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->resolvePlaceholder(currentEntry->username()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->username()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::copyPassword()
|
void DatabaseWidget::copyPassword()
|
||||||
@ -429,7 +429,7 @@ void DatabaseWidget::copyPassword()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->resolvePlaceholder(currentEntry->password()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->password()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::copyURL()
|
void DatabaseWidget::copyURL()
|
||||||
@ -440,7 +440,7 @@ void DatabaseWidget::copyURL()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->resolvePlaceholder(currentEntry->url()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->url()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::copyNotes()
|
void DatabaseWidget::copyNotes()
|
||||||
@ -451,7 +451,7 @@ void DatabaseWidget::copyNotes()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->resolvePlaceholder(currentEntry->notes()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->notes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::copyAttribute(QAction* action)
|
void DatabaseWidget::copyAttribute(QAction* action)
|
||||||
@ -462,7 +462,7 @@ void DatabaseWidget::copyAttribute(QAction* action)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setClipboardTextAndMinimize(currentEntry->attributes()->value(action->text()));
|
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->attributes()->value(action->text())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)
|
void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)
|
||||||
@ -1176,7 +1176,7 @@ bool DatabaseWidget::currentEntryHasUsername()
|
|||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !currentEntry->resolvePlaceholder(currentEntry->username()).isEmpty();
|
return !currentEntry->resolveMultiplePlaceholders(currentEntry->username()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseWidget::currentEntryHasPassword()
|
bool DatabaseWidget::currentEntryHasPassword()
|
||||||
@ -1186,7 +1186,7 @@ bool DatabaseWidget::currentEntryHasPassword()
|
|||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !currentEntry->resolvePlaceholder(currentEntry->password()).isEmpty();
|
return !currentEntry->resolveMultiplePlaceholders(currentEntry->password()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseWidget::currentEntryHasUrl()
|
bool DatabaseWidget::currentEntryHasUrl()
|
||||||
@ -1196,7 +1196,7 @@ bool DatabaseWidget::currentEntryHasUrl()
|
|||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !currentEntry->resolvePlaceholder(currentEntry->url()).isEmpty();
|
return !currentEntry->resolveMultiplePlaceholders(currentEntry->url()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseWidget::currentEntryHasNotes()
|
bool DatabaseWidget::currentEntryHasNotes()
|
||||||
@ -1206,7 +1206,7 @@ bool DatabaseWidget::currentEntryHasNotes()
|
|||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !currentEntry->resolvePlaceholder(currentEntry->notes()).isEmpty();
|
return !currentEntry->resolveMultiplePlaceholders(currentEntry->notes()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupView* DatabaseWidget::groupView() {
|
GroupView* DatabaseWidget::groupView() {
|
||||||
|
@ -139,19 +139,19 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Title:
|
case Title:
|
||||||
result = entry->resolvePlaceholder(entry->title());
|
result = entry->resolveMultiplePlaceholders(entry->title());
|
||||||
if (attr->isReference(EntryAttributes::TitleKey)) {
|
if (attr->isReference(EntryAttributes::TitleKey)) {
|
||||||
result.prepend(tr("Ref: ","Reference abbreviation"));
|
result.prepend(tr("Ref: ","Reference abbreviation"));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case Username:
|
case Username:
|
||||||
result = entry->resolvePlaceholder(entry->username());
|
result = entry->resolveMultiplePlaceholders(entry->username());
|
||||||
if (attr->isReference(EntryAttributes::UserNameKey)) {
|
if (attr->isReference(EntryAttributes::UserNameKey)) {
|
||||||
result.prepend(tr("Ref: ","Reference abbreviation"));
|
result.prepend(tr("Ref: ","Reference abbreviation"));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
case Url:
|
case Url:
|
||||||
result = entry->resolvePlaceholder(entry->url());
|
result = entry->resolveMultiplePlaceholders(entry->url());
|
||||||
if (attr->isReference(EntryAttributes::URLKey)) {
|
if (attr->isReference(EntryAttributes::URLKey)) {
|
||||||
result.prepend(tr("Ref: ","Reference abbreviation"));
|
result.prepend(tr("Ref: ","Reference abbreviation"));
|
||||||
}
|
}
|
||||||
|
@ -588,6 +588,50 @@ void TestGui::testCloneEntry()
|
|||||||
QCOMPARE(entryClone->title(), entryOrg->title() + QString(" - Clone"));
|
QCOMPARE(entryClone->title(), entryOrg->title() + QString(" - Clone"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestGui::testEntryPlaceholders()
|
||||||
|
{
|
||||||
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
||||||
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
||||||
|
|
||||||
|
// Find the new entry action
|
||||||
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
||||||
|
QVERIFY(entryNewAction->isEnabled());
|
||||||
|
|
||||||
|
// Find the button associated with the new entry action
|
||||||
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
||||||
|
QVERIFY(entryNewWidget->isVisible());
|
||||||
|
QVERIFY(entryNewWidget->isEnabled());
|
||||||
|
|
||||||
|
// Click the new entry button and check that we enter edit mode
|
||||||
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||||
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
|
||||||
|
|
||||||
|
// Add entry "test" and confirm added
|
||||||
|
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
||||||
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
||||||
|
QTest::keyClicks(titleEdit, "test");
|
||||||
|
QLineEdit* usernameEdit = editEntryWidget->findChild<QLineEdit*>("usernameEdit");
|
||||||
|
QTest::keyClicks(usernameEdit, "john");
|
||||||
|
QLineEdit* urlEdit = editEntryWidget->findChild<QLineEdit*>("urlEdit");
|
||||||
|
QTest::keyClicks(urlEdit, "{TITLE}.{USERNAME}");
|
||||||
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
||||||
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||||
|
|
||||||
|
QCOMPARE(entryView->model()->rowCount(), 2);
|
||||||
|
|
||||||
|
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
||||||
|
QModelIndex item = entryView->model()->index(1, 1);
|
||||||
|
Entry* entry = entryView->entryFromIndex(item);
|
||||||
|
|
||||||
|
QCOMPARE(entry->title(), QString("test"));
|
||||||
|
QCOMPARE(entry->url(), QString("{TITLE}.{USERNAME}"));
|
||||||
|
|
||||||
|
// Test password copy
|
||||||
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
m_dbWidget->copyURL();
|
||||||
|
QTRY_COMPARE(clipboard->text(), QString("test.john"));
|
||||||
|
}
|
||||||
|
|
||||||
void TestGui::testDragAndDropEntry()
|
void TestGui::testDragAndDropEntry()
|
||||||
{
|
{
|
||||||
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
|
||||||
|
@ -48,6 +48,7 @@ private slots:
|
|||||||
void testSearch();
|
void testSearch();
|
||||||
void testDeleteEntry();
|
void testDeleteEntry();
|
||||||
void testCloneEntry();
|
void testCloneEntry();
|
||||||
|
void testEntryPlaceholders();
|
||||||
void testDragAndDropEntry();
|
void testDragAndDropEntry();
|
||||||
void testDragAndDropGroup();
|
void testDragAndDropGroup();
|
||||||
void testSaveAs();
|
void testSaveAs();
|
||||||
|
Loading…
Reference in New Issue
Block a user