diff --git a/autotests/kemailaddresstest.cpp b/autotests/kemailaddresstest.cpp --- a/autotests/kemailaddresstest.cpp +++ b/autotests/kemailaddresstest.cpp @@ -342,7 +342,6 @@ { QFETCH(QString, input); QFETCH(bool, expResult); - QCOMPARE(isValidSimpleAddress(input), expResult); } diff --git a/src/kemailaddress.cpp b/src/kemailaddress.cpp --- a/src/kemailaddress.cpp +++ b/src/kemailaddress.cpp @@ -21,10 +21,9 @@ #include "kcodecs.h" #include "kcodecs_debug.h" -#include - -#include #include +#include +#include using namespace KEmailAddress; @@ -627,20 +626,24 @@ } } - QString addrRx; + // Anchor the pattern with \A (here) and \z (at the end) + // to match the whole subject string + QString addrRx(QStringLiteral("\\A")); if (localPart[ 0 ] == QLatin1Char('\"') || localPart[ localPart.length() - 1 ] == QLatin1Char('\"')) { - addrRx = QStringLiteral("\"[a-zA-Z@]*[\\w.@-]*[a-zA-Z0-9@]\"@"); + addrRx += QStringLiteral("\"[a-zA-Z@]*[\\w.@-]*[a-zA-Z0-9@]\"@"); } else { - addrRx = QStringLiteral("[a-zA-Z]*[~|{}`\\^?=/+*'&%$#!_\\w.-]*[~|{}`\\^?=/+*'&%$#!_a-zA-Z0-9-]@"); + addrRx += QStringLiteral("[a-zA-Z]*[~|{}`\\^?=/+*'&%$#!_\\w.-]*[~|{}`\\^?=/+*'&%$#!_a-zA-Z0-9-]@"); } if (domainPart[ 0 ] == QLatin1Char('[') || domainPart[ domainPart.length() - 1 ] == QLatin1Char(']')) { - addrRx += QStringLiteral("\\[[0-9]{,3}(\\.[0-9]{,3}){3}\\]"); + addrRx += QStringLiteral("\\[([0-9]{1,3}\\.){1,3}([0-9]{1,3})\\]"); } else { - addrRx += QStringLiteral("[\\w-#]+(\\.[\\w-#]+)*"); + addrRx += QStringLiteral("[\\w#-]+(\\.[\\w#-]+)*"); } - QRegExp rx(addrRx); - return rx.exactMatch(aStr) && !tooManyAtsFlag; + addrRx += QStringLiteral("\\z"); + + QRegularExpression rx(addrRx, QRegularExpression::UseUnicodePropertiesOption); + return rx.match(aStr).hasMatch() && !tooManyAtsFlag; } //----------------------------------------------------------------------------- @@ -1113,7 +1116,7 @@ { QString quoted = str; - QRegExp needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); + QRegularExpression needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x0080-\\xFFFF]")); // avoid double quoting if ((quoted[0] == QLatin1Char('"')) && (quoted[quoted.length() - 1] == QLatin1Char('"'))) { quoted = QLatin1String("\"") + escapeQuotes(quoted.mid(1, quoted.length() - 2)) + QLatin1String("\"");