QUrl: let StripTrailingSlash remove multiple trailing slashes

Change-Id: Ic4c8f70bb729630d9110ed6766dd9e40f9ab4d80
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2013-07-08 14:20:03 +02:00 committed by The Qt Project
parent 0f062f42b9
commit d5d07f26f6
2 changed files with 6 additions and 2 deletions

View File

@ -817,8 +817,10 @@ inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions o
thePath = path.left(slash+1);
}
// check if we need to remove trailing slashes
if ((options & QUrl::StripTrailingSlash) && !thePath.isEmpty() && thePath != QLatin1String("/") && thePath.endsWith(QLatin1Char('/')))
thePath.chop(1);
if (options & QUrl::StripTrailingSlash) {
while (thePath.length() > 1 && thePath.endsWith(QLatin1Char('/')))
thePath.chop(1);
}
if (appendingTo != Path && !(options & QUrl::EncodeDelimiters)) {
if (!qt_urlRecode(appendTo, thePath.constData(), thePath.constEnd(), options, decodedPathInUrlActions))

View File

@ -2521,9 +2521,11 @@ void tst_QUrl::stripTrailingSlash_data()
QTest::newRow("subdir no slash") << "ftp://kde.org/dir/subdir" << "ftp://kde.org/dir/subdir" << "ftp://kde.org/dir/" << "ftp://kde.org/dir";
QTest::newRow("ftp no slash") << "ftp://kde.org/dir" << "ftp://kde.org/dir" << "ftp://kde.org/" << "ftp://kde.org/";
QTest::newRow("ftp slash") << "ftp://kde.org/dir/" << "ftp://kde.org/dir" << "ftp://kde.org/dir/" << "ftp://kde.org/dir";
QTest::newRow("ftp_two_slashes") << "ftp://kde.org/dir//" << "ftp://kde.org/dir" << "ftp://kde.org/dir//" << "ftp://kde.org/dir";
QTest::newRow("file slash") << "file:///dir/" << "file:///dir" << "file:///dir/" << "file:///dir";
QTest::newRow("file no slash") << "file:///dir" << "file:///dir" << "file:///" << "file:///";
QTest::newRow("file root") << "file:///" << "file:///" << "file:///" << "file:///";
QTest::newRow("file_root_manyslashes") << "file://///" << "file:///" << "file://///" << "file:///";
QTest::newRow("no path") << "remote://" << "remote://" << "remote://" << "remote://";
}