From a14a3a5487675a231b912e9a5ae575357d1c2cf8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 12 Jan 2023 08:07:52 -0800 Subject: QUrl: restore empty-but-not-null for components that are present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This got lost during the QStringView port that happend in Qt 6.0 (commit 548dcef08976649c820054f3db1ad108c72439cd) because QString::operator+=(QStringView) does not copy the nullness of the right side, whereas QString::operator+=(const QString &) does. Pick-to: 6.2 6.4 6.5 Fixes: QTBUG-84315 Change-Id: Ide4dbd0777a44ed0870efffd17399b772d34fd55 Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qurl.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/corelib/io/qurl.cpp') diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index f925b2c901..0d42a78422 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -818,14 +818,16 @@ recodeFromUser(const QString &input, const ushort *actions, qsizetype from, qsiz static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options, const ushort *actions) { - // Test ComponentFormattingOptions, ignore FormattingOptions. - if ((options & 0xFFFF0000) == QUrl::PrettyDecoded) { + // The stored value is already QUrl::PrettyDecoded, so there's nothing to + // do if that's what the user asked for (test only + // ComponentFormattingOptions, ignore FormattingOptions). + if ((options & 0xFFFF0000) == QUrl::PrettyDecoded || + !qt_urlRecode(appendTo, value, options, actions)) appendTo += value; - return; - } - if (!qt_urlRecode(appendTo, value, options, actions)) - appendTo += value; + // copy nullness, if necessary, because QString::operator+=(QStringView) doesn't + if (appendTo.isNull() && !value.isNull()) + appendTo.detach(); } inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const -- cgit v1.2.3