summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/text/qbytearray.cpp11
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp18
2 files changed, 26 insertions, 3 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 7f8349131d8..42921e99d76 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -2044,9 +2044,14 @@ QByteArray &QByteArray::prepend(const QByteArray &ba)
QByteArray &QByteArray::append(const QByteArray &ba)
{
- if (size() == 0 && ba.size() > d->freeSpaceAtEnd() && ba.d.isMutable())
- return (*this = ba);
- return append(QByteArrayView(ba));
+ if (!ba.isNull()) {
+ if (isNull()) {
+ operator=(ba);
+ } else if (ba.size()) {
+ append(QByteArrayView(ba));
+ }
+ }
+ return *this;
}
/*!
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index bc84e256514..f5e149836ab 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -53,6 +53,7 @@ private slots:
void append();
void appendExtended_data();
void appendExtended();
+ void appendEmptyNull();
void assign();
void assignShared();
void assignUsesPrependBuffer();
@@ -937,6 +938,23 @@ void tst_QByteArray::appendExtended()
QCOMPARE(array.size(), 11);
}
+void tst_QByteArray::appendEmptyNull()
+{
+ QByteArray a;
+ QVERIFY(a.isEmpty());
+ QVERIFY(a.isNull());
+
+ QByteArray b("");
+ QVERIFY(b.isEmpty());
+ QVERIFY(!b.isNull());
+
+ // Concatenating a null and an empty-but-not-null byte arrays results in
+ // an empty but not null byte array
+ QByteArray r = a + b;
+ QVERIFY(r.isEmpty());
+ QVERIFY(!r.isNull());
+}
+
void tst_QByteArray::assign()
{
// QByteArray &assign(QByteArrayView)