summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-07 23:42:33 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-10 04:04:45 +0000
commite9af2a9519f12cd19d23876dd6a22be911f48372 (patch)
tree8f37bd5f91f9af62c491d00f96611a40d2d9a74a /src
parent9d2788bc8615a09fd7805090673e2c2f5b412a94 (diff)
QString::lastIndexOf: fix off-by-one for zero length matches
Otherwise, it would report that lastIndexOf of an empty pattern in an empty string doesn't exist. Next commit adds extensive autotests; for now, disable a broken autotest (which already features a comment about why it's broken). Change-Id: I9a0e5c0142007f81f5cf93e356c8bd82f00066f7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit be83ff65c424cff1036e7da19d6175826d9f7ed9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstring.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index f88aad1654..102658e7e9 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -4263,13 +4263,13 @@ qsizetype QString::lastIndexOf(const QRegularExpression &re, qsizetype from, QRe
return -1;
}
- qsizetype endpos = (from < 0) ? (size() + from + 1) : (from + 1);
+ qsizetype endpos = (from < 0) ? (size() + from + 1) : (from);
QRegularExpressionMatchIterator iterator = re.globalMatch(*this);
qsizetype lastIndex = -1;
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
qsizetype start = match.capturedStart();
- if (start < endpos) {
+ if (start <= endpos) {
lastIndex = start;
if (rmatch)
*rmatch = std::move(match);