diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 62ad732935..6a02dc165d 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -2561,6 +2561,16 @@ uint qHash(const QUrl &url, uint seed) qHash(url.d->fragment); } +static QUrl adjustFtpPath(QUrl url) +{ + if (url.scheme() == ftpScheme()) { + QString path = url.path(); + if (path.startsWith("//")) + url.setPath(QLatin1String("/%2F") + path.midRef(2)); + } + return url; +} + // The following code has the following copyright: /* @@ -2640,7 +2650,7 @@ QUrl QUrl::fromUserInput(const QString &userInput) && !url.scheme().isEmpty() && (!url.host().isEmpty() || !url.path().isEmpty()) && urlPrepended.port() == -1) - return url; + return adjustFtpPath(url); // Else, try the prepended one and adjust the scheme from the host name if (urlPrepended.isValid() && (!urlPrepended.host().isEmpty() || !urlPrepended.path().isEmpty())) @@ -2649,7 +2659,7 @@ QUrl QUrl::fromUserInput(const QString &userInput) const QString hostscheme = trimmedString.left(dotIndex).toLower(); if (hostscheme == ftpScheme()) urlPrepended.setScheme(ftpScheme()); - return urlPrepended; + return adjustFtpPath(urlPrepended); } return QUrl(); diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 852eb0ab97..a5c11469ad 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2429,6 +2429,10 @@ void tst_QUrl::fromUserInput_data() // FYI: The scheme in the resulting url user QUrl authUrl("user:pass@domain.com"); QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; + + // FTP with double slashes in path + QTest::newRow("ftp-double-slash-1") << "ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath"); + QTest::newRow("ftp-double-slash-1") << "ftp://ftp.example.com//path" << QUrl("ftp://ftp.example.com/%2Fpath"); } void tst_QUrl::fromUserInput()