From 31207b539a19182b48c4b3b8413190d505633eea Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 2 Apr 2025 20:04:24 -0700 Subject: [PATCH] QUrl: restore copying of the input QString in setXxx functions Complements the previous commit by using templates so we copy the input QString if it is a QString, duplicate the input if QStringView. Change-Id: I1646ead1283e16029fc6fffd850daf12b6f6f913 Reviewed-by: David Faure --- src/corelib/io/qurl.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 8f496c09e1a..0492d135d83 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -528,13 +528,13 @@ public: // the "end" parameters are like STL iterators: they point to one past the last valid element bool setScheme(const QString &value, qsizetype len, bool doSetError); void setAuthority(const QString &auth, qsizetype from, qsizetype end, QUrl::ParsingMode mode); - void setUserInfo(QStringView value); - void setUserName(QStringView value); - void setPassword(QStringView value); + template void setUserInfo(String value); + template void setUserName(String value); + template void setPassword(String value); bool setHost(const QString &value, qsizetype from, qsizetype end, QUrl::ParsingMode mode); - void setPath(QStringView value); - void setQuery(QStringView value); - void setFragment(QStringView value); + template void setPath(String value); + template void setQuery(String value); + template void setFragment(String value); inline bool hasScheme() const { return sectionIsPresent & Scheme; } inline bool hasAuthority() const { return sectionIsPresent & Authority; } @@ -814,8 +814,15 @@ static inline void parseDecodedComponent(QString &data, QUrlPrivate::Section sec data.replace(u'[', "%5B"_L1).replace(u']', "%5D"_L1); } -static void -recodeFromUser(QString &output, QStringView input, const ushort *actions) +static void recodeFromUser(QString &output, const QString &input, const ushort *actions) +{ + output.resize(0); + if (qt_urlRecode(output, input, {}, actions)) + return; + output = input; +} + +static void recodeFromUser(QString &output, QStringView input, const ushort *actions) { output.resize(0); if (qt_urlRecode(output, input, {}, actions)) @@ -1086,7 +1093,7 @@ inline void QUrlPrivate::setAuthority(const QString &auth, qsizetype from, qsize port = -1; } -inline void QUrlPrivate::setUserInfo(QStringView value) +template void QUrlPrivate::setUserInfo(String value) { qsizetype delimIndex = value.indexOf(u':'); if (delimIndex < 0) { @@ -1100,31 +1107,31 @@ inline void QUrlPrivate::setUserInfo(QStringView value) } } -inline void QUrlPrivate::setUserName(QStringView value) +template inline void QUrlPrivate::setUserName(String value) { sectionIsPresent |= UserName; recodeFromUser(userName, value, userNameInIsolation); } -inline void QUrlPrivate::setPassword(QStringView value) +template inline void QUrlPrivate::setPassword(String value) { sectionIsPresent |= Password; recodeFromUser(password, value, passwordInIsolation); } -inline void QUrlPrivate::setPath(QStringView value) +template inline void QUrlPrivate::setPath(String value) { // sectionIsPresent |= Path; // not used, save some cycles recodeFromUser(path, value, pathInIsolation); } -inline void QUrlPrivate::setFragment(QStringView value) +template inline void QUrlPrivate::setFragment(String value) { sectionIsPresent |= Fragment; recodeFromUser(fragment, value, fragmentInIsolation); } -inline void QUrlPrivate::setQuery(QStringView value) +template inline void QUrlPrivate::setQuery(String value) { sectionIsPresent |= Query; recodeFromUser(query, value, queryInIsolation);