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.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index b320624b28..6452c0fc80 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -176,7 +176,6 @@
*/
#include "qplatformdefs.h"
#include "qurl.h"
-#include "private/qunicodetables_p.h"
#include "qatomic.h"
#include "qbytearray.h"
#include "qdir.h"
@@ -3464,9 +3463,8 @@ QString QUrlPrivate::canonicalHost() const
that->host = host.toLower();
} else {
that->host = qt_ACE_do(host, NormalizeAce);
- if (that->host.isNull())
- that->isHostValid = false;
}
+ that->isHostValid = !that->host.isNull();
return that->host;
}
@@ -3781,6 +3779,10 @@ void QUrlPrivate::validate() const
QString auth = authority(); // causes the non-encoded forms to be valid
+ // authority() calls canonicalHost() which sets this
+ if (!isHostValid)
+ return;
+
if (scheme == QLatin1String("mailto")) {
if (!host.isEmpty() || port != -1 || !userName.isEmpty() || !password.isEmpty()) {
that->isValid = false;
@@ -3954,9 +3956,10 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const
url += scheme.toLatin1();
url += ':';
}
+ QString savedHost = host; // pre-validation, may be invalid!
QString auth = authority();
bool doFileScheme = scheme == QLatin1String("file") && encodedPath.startsWith('/');
- if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority && (!auth.isEmpty() || doFileScheme)) {
+ if ((options & QUrl::RemoveAuthority) != QUrl::RemoveAuthority && (!auth.isEmpty() || doFileScheme || !savedHost.isEmpty())) {
if (doFileScheme && !encodedPath.startsWith('/'))
url += '/';
url += "//";
@@ -3982,6 +3985,12 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const
url += '[';
url += host.toLatin1();
url += ']';
+ } else if (host.isEmpty() && !savedHost.isEmpty()) {
+ // this case is only possible with an invalid URL
+ // it's here only so that we can keep the original, invalid hostname
+ // in encodedOriginal.
+ // QUrl::isValid() will return false, so toEncoded() can be anything (it's not valid)
+ url += savedHost.toUtf8();
} else {
url += QUrl::toAce(host);
}
@@ -4101,7 +4110,7 @@ const QByteArray &QUrlPrivate::normalized() const
QString QUrlPrivate::createErrorString()
{
- if (isValid)
+ if (isValid && isHostValid)
return QString();
QString errorString(QLatin1String(QT_TRANSLATE_NOOP(QUrl, "Invalid URL \"")));
@@ -4125,7 +4134,10 @@ QString QUrlPrivate::createErrorString()
errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, "\'"));
} else {
errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ": "));
- errorString += QLatin1String(errorInfo._message);
+ if (isHostValid)
+ errorString += QLatin1String(errorInfo._message);
+ else
+ errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, "invalid hostname"));
}
if (errorInfo._found) {
errorString += QLatin1String(QT_TRANSLATE_NOOP(QUrl, ", but found \'"));
@@ -4488,7 +4500,7 @@ void QUrl::setAuthority(const QString &authority)
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
- QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
+ QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized | QUrlPrivate::HostCanonicalized);
d->setAuthority(authority);
}