summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 0c81af52d7..50512a4a73 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -413,7 +413,6 @@
#include "qstringlist.h"
#include "qdebug.h"
#include "qhash.h"
-#include "qdir.h" // for QDir::fromNativeSeparators
#include "qdatastream.h"
#if QT_CONFIG(topleveldomain) // ### Qt6: Remove section
#include "qtldurl_p.h"
@@ -1267,10 +1266,16 @@ static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end
zoneId = decoded.mid(zoneIdPosition + zoneIdIdentifier.size());
endBeforeZoneId = decoded.constBegin() + zoneIdPosition;
+ // was there anything after the zone ID separator?
if (zoneId.isEmpty())
return end;
}
+ // did the address become empty after removing the zone ID?
+ // (it might have always been empty)
+ if (decoded.constBegin() == endBeforeZoneId)
+ return end;
+
const QChar *ret = QIPAddressUtils::parseIp6(address, decoded.constBegin(), endBeforeZoneId);
if (ret)
return begin + (ret - decoded.constBegin());
@@ -3635,6 +3640,8 @@ bool QUrl::operator <(const QUrl &url) const
/*!
Returns \c true if this URL and the given \a url are equal;
otherwise returns \c false.
+
+ \sa matches()
*/
bool QUrl::operator ==(const QUrl &url) const
{
@@ -3742,6 +3749,8 @@ bool QUrl::matches(const QUrl &url, FormattingOptions options) const
/*!
Returns \c true if this URL and the given \a url are not equal;
otherwise returns \c false.
+
+ \sa matches()
*/
bool QUrl::operator !=(const QUrl &url) const
{
@@ -3810,6 +3819,25 @@ bool QUrl::isDetached() const
return !d || d->ref.loadRelaxed() == 1;
}
+static QString fromNativeSeparators(const QString &pathName)
+{
+#if defined(Q_OS_WIN)
+ QString result(pathName);
+ const QChar nativeSeparator = u'\\';
+ auto i = result.indexOf(nativeSeparator);
+ if (i != -1) {
+ QChar * const data = result.data();
+ const auto length = result.length();
+ for (; i < length; ++i) {
+ if (data[i] == nativeSeparator)
+ data[i] = u'/';
+ }
+ }
+ return result;
+#else
+ return pathName;
+#endif
+}
/*!
Returns a QUrl representation of \a localFile, interpreted as a local
@@ -3848,7 +3876,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
if (localFile.isEmpty())
return url;
QString scheme = fileScheme();
- QString deslashified = QDir::fromNativeSeparators(localFile);
+ QString deslashified = fromNativeSeparators(localFile);
// magic for drives on windows
if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
@@ -3862,12 +3890,20 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
hostSpec.truncate(hostSpec.size() - 4);
scheme = webDavScheme();
}
- url.setHost(hostSpec.toString());
- if (indexOfPath > 2)
+ // hosts can't be IPv6 addresses without [], so we can use QUrlPrivate::setHost
+ url.detach();
+ if (!url.d->setHost(hostSpec.toString(), 0, hostSpec.size(), StrictMode)) {
+ if (url.d->error->code != QUrlPrivate::InvalidRegNameError)
+ return url;
+
+ // Path hostname is not a valid URL host, so set it entirely in the path
+ // (by leaving deslashified unchanged)
+ } else if (indexOfPath > 2) {
deslashified = deslashified.right(deslashified.length() - indexOfPath);
- else
+ } else {
deslashified.clear();
+ }
}
url.setScheme(scheme);