QUrl::toString: fix using of NormalizePathSegments and RemoveFilename
We were overwriting the normalization if RemoveFilename was used. [ChangeLog][QtCore][QUrl] Fixed a bug that caused QUrl::toString(), QUrl::toEncoded() and QUrl::adjusted() to ignore QUrl::NormalizePathSegments if QUrl::RemoveFilename was set. Fixes: QTBUG-127711 Change-Id: I8a96935cf6c742259c9dfffd17e8e1f7fec44cb6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit c9ff625865c355fb57c824b13f3cb4b26e53fbe7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit fee6283b85de8a06be10aee180b37ec3e479c9b7)
This commit is contained in:
parent
492c646735
commit
e4b298316d
@ -916,10 +916,10 @@ inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions o
|
|||||||
|
|
||||||
QStringView thePathView(thePath);
|
QStringView thePathView(thePath);
|
||||||
if (options & QUrl::RemoveFilename) {
|
if (options & QUrl::RemoveFilename) {
|
||||||
const qsizetype slash = path.lastIndexOf(u'/');
|
const qsizetype slash = thePathView.lastIndexOf(u'/');
|
||||||
if (slash == -1)
|
if (slash == -1)
|
||||||
return;
|
return;
|
||||||
thePathView = QStringView{path}.left(slash + 1);
|
thePathView = thePathView.left(slash + 1);
|
||||||
}
|
}
|
||||||
// check if we need to remove trailing slashes
|
// check if we need to remove trailing slashes
|
||||||
if (options & QUrl::StripTrailingSlash) {
|
if (options & QUrl::StripTrailingSlash) {
|
||||||
|
@ -2927,6 +2927,7 @@ void tst_QUrl::stripTrailingSlash_data()
|
|||||||
QTest::newRow("file root") << "file:///" << "file:///" << "file:///" << "file:///";
|
QTest::newRow("file root") << "file:///" << "file:///" << "file:///" << "file:///";
|
||||||
QTest::newRow("file_root_manyslashes") << "file://///" << "file:///" << "file://///" << "file:///";
|
QTest::newRow("file_root_manyslashes") << "file://///" << "file:///" << "file://///" << "file:///";
|
||||||
QTest::newRow("no path") << "remote://" << "remote://" << "remote://" << "remote://";
|
QTest::newRow("no path") << "remote://" << "remote://" << "remote://" << "remote://";
|
||||||
|
QTest::newRow("no authority") << "/root/test/../foo/bar" << "/root/test/../foo/bar" << "/root/test/../foo/" << "/root/test/../foo";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QUrl::stripTrailingSlash()
|
void tst_QUrl::stripTrailingSlash()
|
||||||
@ -4370,30 +4371,67 @@ void tst_QUrl::normalizeRemotePaths_data()
|
|||||||
{
|
{
|
||||||
QTest::addColumn<QUrl>("url");
|
QTest::addColumn<QUrl>("url");
|
||||||
QTest::addColumn<QString>("expected");
|
QTest::addColumn<QString>("expected");
|
||||||
|
QTest::addColumn<QString>("expectedNoFilename");
|
||||||
|
|
||||||
QTest::newRow("dotdot-slashslash") << QUrl("http://qt-project.org/some/long/..//path") << "http://qt-project.org/some//path";
|
QTest::newRow("dotdot-slashslash") << QUrl("http://qt-project.org/some/long/..//path")
|
||||||
QTest::newRow("slashslash-dotdot") << QUrl("http://qt-project.org/some//../path") << "http://qt-project.org/some/path";
|
<< "http://qt-project.org/some//path"
|
||||||
QTest::newRow("slashslash-dotdot2") << QUrl("http://qt-project.org/some//path/../") << "http://qt-project.org/some//";
|
<< "http://qt-project.org/some//";
|
||||||
QTest::newRow("dot-slash") << QUrl("http://qt-project.org/some/./path") << "http://qt-project.org/some/path";
|
QTest::newRow("slashslash-dotdot") << QUrl("http://qt-project.org/some//../path")
|
||||||
QTest::newRow("slashslash-dot-slashslash") << QUrl("http://qt-project.org/some//.//path") << "http://qt-project.org/some///path";
|
<< "http://qt-project.org/some/path"
|
||||||
QTest::newRow("dot-slashslash") << QUrl("http://qt-project.org/some/.//path") << "http://qt-project.org/some//path";
|
<< "http://qt-project.org/some/";
|
||||||
QTest::newRow("multiple-slashes") << QUrl("http://qt-project.org/some//path") << "http://qt-project.org/some//path";
|
QTest::newRow("slashslash-dotdot2") << QUrl("http://qt-project.org/some//path/../")
|
||||||
QTest::newRow("multiple-slashes4") << QUrl("http://qt-project.org/some////path") << "http://qt-project.org/some////path";
|
<< "http://qt-project.org/some//"
|
||||||
QTest::newRow("slashes-at-end") << QUrl("http://qt-project.org/some//") << "http://qt-project.org/some//";
|
<< "http://qt-project.org/some//";
|
||||||
QTest::newRow("dot-dotdot") << QUrl("http://qt-project.org/path/./../") << "http://qt-project.org/";
|
QTest::newRow("dot-slash") << QUrl("http://qt-project.org/some/./path")
|
||||||
QTest::newRow("slash-dot-slash-dot-slash") << QUrl("http://qt-project.org/path//.//.//") << "http://qt-project.org/path////";
|
<< "http://qt-project.org/some/path"
|
||||||
QTest::newRow("dotdot") << QUrl("http://qt-project.org/../") << "http://qt-project.org/";
|
<< "http://qt-project.org/some/";
|
||||||
QTest::newRow("dotdot-dotdot") << QUrl("http://qt-project.org/path/../../") << "http://qt-project.org/";
|
QTest::newRow("slashslash-dot-slashslash") << QUrl("http://qt-project.org/some//.//path")
|
||||||
QTest::newRow("dot-dotdot-tail") << QUrl("http://qt-project.org/stem/path/./../tail") << "http://qt-project.org/stem/tail";
|
<< "http://qt-project.org/some///path"
|
||||||
QTest::newRow("slash-dotdot-slash-tail") << QUrl("http://qt-project.org/stem/path//..//tail") << "http://qt-project.org/stem/path//tail";
|
<< "http://qt-project.org/some///";
|
||||||
|
QTest::newRow("dot-slashslash") << QUrl("http://qt-project.org/some/.//path")
|
||||||
|
<< "http://qt-project.org/some//path"
|
||||||
|
<< "http://qt-project.org/some//";
|
||||||
|
QTest::newRow("multiple-slashes") << QUrl("http://qt-project.org/some//path")
|
||||||
|
<< "http://qt-project.org/some//path"
|
||||||
|
<< "http://qt-project.org/some//";
|
||||||
|
QTest::newRow("multiple-slashes4") << QUrl("http://qt-project.org/some////path")
|
||||||
|
<< "http://qt-project.org/some////path"
|
||||||
|
<< "http://qt-project.org/some////";
|
||||||
|
QTest::newRow("slashes-at-end") << QUrl("http://qt-project.org/some//")
|
||||||
|
<< "http://qt-project.org/some//"
|
||||||
|
<< "http://qt-project.org/some//";
|
||||||
|
QTest::newRow("dot-dotdot") << QUrl("http://qt-project.org/path/./../")
|
||||||
|
<< "http://qt-project.org/"
|
||||||
|
<< "http://qt-project.org/";
|
||||||
|
QTest::newRow("slash-dot-slash-dot-slash") << QUrl("http://qt-project.org/path//.//.//")
|
||||||
|
<< "http://qt-project.org/path////"
|
||||||
|
<< "http://qt-project.org/path////";
|
||||||
|
QTest::newRow("dotdot") << QUrl("http://qt-project.org/../")
|
||||||
|
<< "http://qt-project.org/"
|
||||||
|
<< "http://qt-project.org/";
|
||||||
|
QTest::newRow("dotdot-tail") << QUrl("http://qt-project.org/root/test/../foo/bar")
|
||||||
|
<< "http://qt-project.org/root/foo/bar"
|
||||||
|
<< "http://qt-project.org/root/foo/";
|
||||||
|
QTest::newRow("dotdot-dotdot") << QUrl("http://qt-project.org/path/../../")
|
||||||
|
<< "http://qt-project.org/"
|
||||||
|
<< "http://qt-project.org/";
|
||||||
|
QTest::newRow("dot-dotdot-tail") << QUrl("http://qt-project.org/stem/path/./../tail")
|
||||||
|
<< "http://qt-project.org/stem/tail"
|
||||||
|
<< "http://qt-project.org/stem/";
|
||||||
|
QTest::newRow("slash-dotdot-slash-tail") << QUrl("http://qt-project.org/stem/path//..//tail")
|
||||||
|
<< "http://qt-project.org/stem/path//tail"
|
||||||
|
<< "http://qt-project.org/stem/path//";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QUrl::normalizeRemotePaths()
|
void tst_QUrl::normalizeRemotePaths()
|
||||||
{
|
{
|
||||||
QFETCH(QUrl, url);
|
QFETCH(QUrl, url);
|
||||||
QFETCH(QString, expected);
|
QFETCH(QString, expected);
|
||||||
|
QFETCH(QString, expectedNoFilename);
|
||||||
|
|
||||||
QCOMPARE(url.adjusted(QUrl::NormalizePathSegments).toString(), expected);
|
QCOMPARE(url.adjusted(QUrl::NormalizePathSegments).toString(), expected);
|
||||||
|
QCOMPARE(url.adjusted(QUrl::NormalizePathSegments | QUrl::RemoveFilename).toString(),
|
||||||
|
expectedNoFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QUrl)
|
QTEST_MAIN(tst_QUrl)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user