summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2021-08-16 20:20:48 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2021-08-18 10:21:04 +0300
commit61525c4f41f0053099c461aa016f7eea062e6555 (patch)
treef0cae2208d0d40ea92c3bfe1bcaa50221570ef04
parentb3676ddd0a541decf193abb6605b20d93c07f7f9 (diff)
Revert "QString::lastIndexOf: fix off-by-one for zero length matches"
This reverts commit 3a273ac47f20e82a1f2f63411b210025ca0f4495. The revert is needed as QString::lastIndexOf was broken after the original patch. Task-number: QTBUG-94215 Change-Id: Ic1c81daa7b5ce8861911210ff34049ed7704ed4a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/text/qstring.cpp4
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 3c08d970ed..bac6d20c0c 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -4562,13 +4562,13 @@ int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpress
return -1;
}
- int endpos = (from < 0) ? (size() + from + 1) : (from);
+ int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
QRegularExpressionMatchIterator iterator = re.globalMatch(*this);
int lastIndex = -1;
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
int start = match.capturedStart();
- if (start <= endpos) {
+ if (start < endpos) {
lastIndex = start;
if (rmatch)
*rmatch = std::move(match);
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 49dc23a695..696b8159ac 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -1675,7 +1675,7 @@ void tst_QString::lastIndexOf()
QCOMPARE(haystack.lastIndexOf(needle.toLatin1(), from, cs), expected);
QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from, cs), expected);
- if (from >= -1 && from < haystack.size() && needle.size() > 0) {
+ if (from >= -1 && from < haystack.size()) {
// unfortunately, QString and QRegExp don't have the same out of bound semantics
// I think QString is wrong -- See file log for contact information.
{