QUrl::fromUserInput: fix for urls without a host.
QUrl::fromUserInput("http://") was invalid, which doesn't make sense
since QUrl("http://") is valid. Same for "smb:" which is actually
even more a valid URL from a user's point of view.
Change-Id: I371ac393d61b49499edf5adbbc2a90b426fe9e5d
Reviewed-by: Marco Martin <mart@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
69627730ea
commit
8b2728ec38
|
|
@ -3878,12 +3878,11 @@ QUrl QUrl::fromUserInput(const QString &userInput)
|
|||
QUrl url = QUrl(trimmedString, QUrl::TolerantMode);
|
||||
QUrl urlPrepended = QUrl(QStringLiteral("http://") + trimmedString, QUrl::TolerantMode);
|
||||
|
||||
// Check the most common case of a valid url with scheme and host
|
||||
// Check the most common case of a valid url with a scheme
|
||||
// We check if the port would be valid by adding the scheme to handle the case host:port
|
||||
// where the host would be interpretted as the scheme
|
||||
if (url.isValid()
|
||||
&& !url.scheme().isEmpty()
|
||||
&& (!url.host().isEmpty() || !url.path().isEmpty())
|
||||
&& urlPrepended.port() == -1)
|
||||
return adjustFtpPath(url);
|
||||
|
||||
|
|
|
|||
|
|
@ -2617,6 +2617,10 @@ void tst_QUrl::fromUserInput_data()
|
|||
QTest::newRow("add scheme-2") << "ftp.example.org" << QUrl("ftp://ftp.example.org");
|
||||
QTest::newRow("add scheme-3") << "hostname" << QUrl("http://hostname");
|
||||
|
||||
// no host
|
||||
QTest::newRow("nohost-1") << "http://" << QUrl("http://");
|
||||
QTest::newRow("nohost-2") << "smb:" << QUrl("smb:");
|
||||
|
||||
// QUrl's tolerant parser should already handle this
|
||||
QTest::newRow("not-encoded-0") << "http://example.org/test page.html" << QUrl::fromEncoded("http://example.org/test%20page.html");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue