diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-12-09 14:58:03 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-12-11 14:26:04 +0100 |
| commit | 24f53274ae2a037f6455baa366e2665d6e3e620b (patch) | |
| tree | 667d2364d18afb40d732344659614c445ff0e1e4 /src/qml/jsruntime/qv4stringobject.cpp | |
| parent | 2401eacdc7bd6072ac18ef4715c4b2e433bb57ef (diff) | |
QtQml: Re-fix regular expressions with multiple matches
We should only bump the previous match if it was of size 0. Otherwise
oldSize + 1 is already one-past-end.
Amends commit 9d9413f3d3983b1d24fd878da14eed153e83cbaa.
Pick-to: 6.9 6.8 6.5
Fixes: QTBUG-132050
Change-Id: I5d6e85143723a2695c639109b68ee8df7d0fef50
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: <carl@carlschwan.eu>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index f7c7eae199..e4aacc3d2a 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -778,7 +778,14 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val nMatchOffsets += re->captureCount() * 2; if (!regExp->global()) break; - offset = qMax(offset, matchOffsets[oldSize + 1]) + 1; + + const uint matchBegin = matchOffsets[oldSize]; + const uint matchEnd = matchOffsets[oldSize + 1]; + + // If we have a zero-sized match, don't match at the same place again. + const uint matchOffset = (matchBegin == matchEnd) ? matchEnd + 1 : matchEnd; + + offset = std::max(offset + 1, matchOffset); } if (regExp->global()) { regExp->setLastIndex(0); |
