Adjust a double leading slash in the path for FTP to /%2F
Some FTP implementations (currently not including QNAM) strip the first slash off the path in an FTP URL so that the path in the URL is relative to the login path (the user's home directory). To reach the root directory, another slash is necessary, hence the double slash. In anticipation of future URL normalisation, which Qt 4 could do, "//" could be rendered to "/", so this extra slash should be "%2F". This operation is done only in QUrl::fromUserInput. Change-Id: If9619ef6b546a3f4026cb26b74a7a5a865123609 Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
parent
81d1f79a7f
commit
d4f3052a1b
@ -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();
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user