diff --git a/src/api/KWallet/kwallet.cpp b/src/api/KWallet/kwallet.cpp --- a/src/api/KWallet/kwallet.cpp +++ b/src/api/KWallet/kwallet.cpp @@ -176,13 +176,16 @@ attrs[KSS_ATTR_ENTRYFOLDER] = folder; KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs); if (searchItemsJob->exec()) { - QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard); + const QRegularExpression re(QRegularExpression::anchoredPattern( + QRegularExpression::wildcardToRegularExpression(key))); const auto list = searchItemsJob->items(); + QRegularExpressionMatch match; for (KSecretsService::SearchCollectionItemsJob::Item item : list) { KSecretsService::ReadItemPropertyJob *readLabelJob = item->label(); if (readLabelJob->exec()) { QString label = readLabelJob->propertyValue().toString(); - if (re.exactMatch(label)) { + match = re.match(label); + if (match.hasMatch()) { if (verb(this, label, item.data())) { rc = 0; // one successful iteration already produced results, so success return } diff --git a/src/runtime/kwalletd/backend/kwalletbackend.cc b/src/runtime/kwalletd/backend/kwalletbackend.cc --- a/src/runtime/kwalletd/backend/kwalletbackend.cc +++ b/src/runtime/kwalletd/backend/kwalletbackend.cc @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -530,11 +530,14 @@ return rc; } - QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard); + QRegularExpression re(QRegularExpression::anchoredPattern( + QRegularExpression::wildcardToRegularExpression(key))); const EntryMap &map = _entries[_folder]; + QRegularExpressionMatch match; for (EntryMap::ConstIterator i = map.begin(); i != map.end(); ++i) { - if (re.exactMatch(i.key())) { + match = re.match(i.key()); + if (match.hasMatch()) { rc.append(i.value()); } } diff --git a/src/runtime/kwalletd/kwalletd.cpp b/src/runtime/kwalletd/kwalletd.cpp --- a/src/runtime/kwalletd/kwalletd.cpp +++ b/src/runtime/kwalletd/kwalletd.cpp @@ -215,6 +215,8 @@ return qMakePair(-1, static_cast(nullptr)); } +const QRegularExpression walletRegex( + QStringLiteral("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\.\\+\\_\\s]+$")); bool KWalletD::_processing = false; void KWalletD::processTransactions() @@ -331,8 +333,7 @@ return -1; } - if (!QRegExp(QString::fromLatin1("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\." - "\\+\\_\\s]+$")).exactMatch(wallet)) { + if (!walletRegex.match(wallet).hasMatch()) { return -1; } @@ -363,8 +364,7 @@ return -1; } - if (!QRegExp(QString::fromLatin1("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\." - "\\+\\_\\s]+$")).exactMatch(wallet)) { + if (!walletRegex.match(wallet).hasMatch()) { return -1; } @@ -1871,8 +1871,7 @@ return -1; } - if (!QRegExp(QString::fromLatin1("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\." - "\\+\\_\\s]+$")).exactMatch(wallet)) { + if (!walletRegex.match(wallet).hasMatch()) { return -1; }