diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 4ba957128ff..3088396eb82 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -2532,12 +2532,19 @@ QByteArray &QByteArray::replace(QByteArrayView before, QByteArrayView after) const char *a = after.data(); qsizetype asize = after.size(); + if (isEmpty()) { + if (bsize) + return *this; + } else { + if (b == a && bsize == asize) + return *this; + } + if (asize == 0 && bsize == 0) + return *this; + if (bsize == 1 && asize == 1) return replace(*b, *a); // use the fast char-char algorithm - if (isNull() || (b == a && bsize == asize)) - return *this; - // protect against before or after being part of this std::string pinnedNeedle, pinnedReplacement; if (QtPrivate::q_points_into_range(a, d)) { diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index a160b81c006..582082a0442 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -3864,7 +3864,7 @@ QString &QString::replace(const QChar *before, qsizetype blen, const QChar *after, qsizetype alen, Qt::CaseSensitivity cs) { - if (d.size == 0) { + if (isEmpty()) { if (blen) return *this; } else { diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp index 0db6f848d3a..6b09c270915 100644 --- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp @@ -1590,15 +1590,7 @@ void tst_QByteArray::replaceWithEmptyNeedleInsertsBeforeEachChar() // shared auto copy = haystack; copy.replace(needle, replacement); - if (isByteArray) { - QEXPECT_FAIL("///a/", "QTBUG-134079", Continue); - QEXPECT_FAIL("///a/", "QTBUG-134079", Continue); - } QCOMPARE(copy.isNull(), result.isNull()); - if (isByteArray) { - QEXPECT_FAIL("///a/", "QTBUG-134079", Continue); - QEXPECT_FAIL("///a/", "QTBUG-134079", Continue); - } QCOMPARE(copy, result); } { diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 9d2af3755e8..2280ea6ab0e 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -2543,19 +2543,11 @@ void tst_QStringApiSymmetry::replace_split_impl() const { auto copy = haystack; copy.replace(needle, replacement); - if constexpr (std::is_same_v) { - QEXPECT_FAIL("null ~= null$", "QTBUG-134079", Continue); - QEXPECT_FAIL("null ~= empty$", "QTBUG-134079", Continue); - } QCOMPARE(copy, result); } { auto copy = detached(haystack); copy.replace(needle, replacement); - if constexpr (std::is_same_v) { - QEXPECT_FAIL("null ~= null$", "QTBUG-134079", Continue); - QEXPECT_FAIL("null ~= empty$", "QTBUG-134079", Continue); - } QCOMPARE(copy, result); } }