From 71ed74e72e4d3c643381fa1b4a276c0609393df2 Mon Sep 17 00:00:00 2001
From: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Date: Mon, 10 Nov 2014 12:53:31 +0100
Subject: [PATCH] Allow empty string as intermediate match

QRegularExpressionValidator and QRegularExpression disagree on what a
partial match means.

[ChangeLog][QtGui][QRegularExpressionValidator] Allow empty string as
intermediate match

Change-Id: Ia6c55beb54870b1be5c88b6ef3eceebc8ca3f86b
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
---
 src/gui/util/qvalidator.cpp                                    | 2 +-
 .../tst_qregularexpressionvalidator.cpp                        | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp
index 93990a87484..aac92827100 100644
--- a/src/gui/util/qvalidator.cpp
+++ b/src/gui/util/qvalidator.cpp
@@ -1013,7 +1013,7 @@ QValidator::State QRegularExpressionValidator::validate(QString &input, int &pos
     const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
     if (m.hasMatch()) {
         return Acceptable;
-    } else if (m.hasPartialMatch()) {
+    } else if (input.isEmpty() || m.hasPartialMatch()) {
         return Intermediate;
     } else {
         pos = input.size();
diff --git a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
index 31853f7015f..eff07ad07f0 100644
--- a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
+++ b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
@@ -74,6 +74,9 @@ void tst_QRegularExpressionValidator::validate_data()
     QTest::newRow("data14") << QRegularExpression("\\w\\d\\d") << QString("E5") << QValidator::Intermediate;
     QTest::newRow("data15") << QRegularExpression("\\w\\d\\d") << QString("+9") << QValidator::Invalid;
 
+    QTest::newRow("emptystr1") << QRegularExpression("[T][e][s][t]") << QString("") << QValidator::Intermediate;
+    QTest::newRow("emptystr2") << QRegularExpression("[T][e][s][t]") << QString() << QValidator::Intermediate;
+
     QTest::newRow("empty01") << QRegularExpression() << QString() << QValidator::Acceptable;
     QTest::newRow("empty02") << QRegularExpression() << QString("test") << QValidator::Acceptable;
 }
-- 
GitLab