diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 00588da15f..f8a8bd18e3 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -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)) diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index c8945e677c..bfd9c55c9e 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -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://"; }