From b98b7de0da395be33e2d1646ac62075422ce4343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 1 Sep 2020 09:07:09 +0200 Subject: QByteArray: Disregard space at front during ::reserve(...) Traditionally when calling reserve it's because you expect to append up to X amount of bytes. We should keep that behavior the same. With another patch still in the works current behavior caused an issue with QStringBuilder in QNAM, as mirrored in the testcase attached. Change-Id: I9792a8f158fc9235e3de48ac8b06ac2c10e7f3dc Reviewed-by: Andrei Golubev Reviewed-by: Lars Knoll --- .../corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib/text/qstringbuilder/qstringbuilder1') diff --git a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp index b811c63036..e0a261efd0 100644 --- a/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/text/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -344,6 +344,14 @@ void runScenario() QByteArray ba2 = withZero; ba2 += ba2 P withZero; QCOMPARE(ba2, QByteArray(withZero + withZero + withZero)); + + // With space allocated in front, mirroring what happens with QHttpMultiPart in QNAM + QByteArray byteArray; + byteArray.reserve(70); + byteArray.insert(0, "multipart/"); + byteArray.insert(byteArray.size(), "mixed"); + byteArray += "; boundary=\"" P QByteArray(30, 'o') P '"'; + QCOMPARE(byteArray, "multipart/mixed; boundary=\"oooooooooooooooooooooooooooooo\""); } } -- cgit v1.2.3