diff --git a/src/kauthaction.cpp b/src/kauthaction.cpp --- a/src/kauthaction.cpp +++ b/src/kauthaction.cpp @@ -20,7 +20,7 @@ #include "kauthaction.h" #include -#include +#include class QWidget; @@ -123,8 +123,10 @@ d->valid = BackendsManager::authBackend()->actionExists(name); } else { // Otherwise, check through a regexp - QRegExp exp(QLatin1String("[0-z]+(\\.[0-z]+)*")); - d->valid = exp.exactMatch(name); + // TODO: with Qt 5.12 QRegularExpression::anchoredPattern() can be used instead + // of \A and \z anchors + QRegularExpression re(QStringLiteral("\\A[0-z]+(\\.[0-z]+)*\\z")); + d->valid = re.match(name).hasMatch(); } } diff --git a/src/policy-gen/policy-gen.cpp b/src/policy-gen/policy-gen.cpp --- a/src/policy-gen/policy-gen.cpp +++ b/src/policy-gen/policy-gen.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -71,13 +71,17 @@ QList parse(QSettings &ini) { QList actions; - QRegExp actionExp(QLatin1String("[0-9a-z]+(\\.[0-9a-z]+)*")); - QRegExp descriptionExp(QLatin1String("description(?:\\[(\\w+)\\])?")); - QRegExp nameExp(QLatin1String("name(?:\\[(\\w+)\\])?")); - QRegExp policyExp(QLatin1String("yes|no|auth_self|auth_admin")); + // TODO: with Qt 5.12 QRegularExpression::anchoredPattern() can be used instead of the + // \A and \z anchors + QRegularExpression actionExp(QStringLiteral("\\A[0-9a-z]+(\\.[0-9a-z]+)*\\z")); - descriptionExp.setCaseSensitivity(Qt::CaseInsensitive); - nameExp.setCaseSensitivity(Qt::CaseInsensitive); + QRegularExpression descriptionExp(QStringLiteral("\\Adescription(?:\\[(\\w+)\\])?\\z") + , QRegularExpression::CaseInsensitiveOption); + + QRegularExpression nameExp(QStringLiteral("\\Aname(?:\\[(\\w+)\\])?\\z") + , QRegularExpression::CaseInsensitiveOption); + + QRegularExpression policyExp(QStringLiteral("\\A(?:yes|no|auth_self|auth_admin)\\z")); const auto listChilds = ini.childGroups(); for (const QString &name : listChilds) { @@ -87,7 +91,7 @@ continue; } - if (!actionExp.exactMatch(name)) { + if (!actionExp.match(name).hasMatch()) { qCritical("Wrong action syntax: %s\n", name.toLatin1().data()); exit(1); } @@ -97,17 +101,18 @@ const auto listChildKeys = ini.childKeys(); for (const QString &key : listChildKeys) { - if (descriptionExp.exactMatch(key)) { - QString lang = descriptionExp.capturedTexts().at(1); + QRegularExpressionMatch match; + if ((match = descriptionExp.match(key)).hasMatch()) { + QString lang = match.captured(); if (lang.isEmpty()) { lang = QString::fromLatin1("en"); } action.descriptions.insert(lang, ini.value(key).toString()); - } else if (nameExp.exactMatch(key)) { - QString lang = nameExp.capturedTexts().at(1); + } else if ((match = nameExp.match(key)).hasMatch()) { + QString lang = match.captured(); if (lang.isEmpty()) { lang = QString::fromLatin1("en"); @@ -117,15 +122,15 @@ } else if (key.toLower() == QLatin1String("policy")) { QString policy = ini.value(key).toString(); - if (!policyExp.exactMatch(policy)) { + if (!policyExp.match(policy).hasMatch()) { qCritical("Wrong policy: %s", policy.toLatin1().data()); exit(1); } action.policy = policy; } else if (key.toLower() == QLatin1String("policyinactive")) { QString policyInactive = ini.value(key).toString(); - if (!policyExp.exactMatch(policyInactive)) { + if (!policyExp.match(policyInactive).hasMatch()) { qCritical("Wrong policy: %s", policyInactive.toLatin1().data()); exit(1); }