diff options
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); |
