From e8192883b2d00b7a1b68fb7c7154a1e75bab0b26 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 1 Sep 2011 15:04:33 +0100 Subject: Fix comparison of absolute, unclean paths in QDir QDir::operator== was creating a clean absolute path for comparison purposes if the original path was relative. However original absolute paths were trusted, even though they could be unclean. Now they are checked for cleanliness first. Task-Number: QTBUG-19995 Task-Number: QTBUG-20495 Change-Id: I047a1a40ae5151e4604085e4ac87f30a4e4979c4 Reviewed-on: http://codereview.qt.nokia.com/4099 Reviewed-by: Qt Sanity Bot Reviewed-by: Prasanth Ullattil --- .../auto/qfilesystementry/tst_qfilesystementry.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/auto/qfilesystementry/tst_qfilesystementry.cpp') diff --git a/tests/auto/qfilesystementry/tst_qfilesystementry.cpp b/tests/auto/qfilesystementry/tst_qfilesystementry.cpp index 016bcbfe8a..2daabee48f 100644 --- a/tests/auto/qfilesystementry/tst_qfilesystementry.cpp +++ b/tests/auto/qfilesystementry/tst_qfilesystementry.cpp @@ -68,6 +68,8 @@ private slots: void absoluteOrRelative_data(); void absoluteOrRelative(); #endif + void isClean_data(); + void isClean(); }; #if defined(WIN_STUFF) @@ -383,5 +385,35 @@ void tst_QFileSystemEntry::absoluteOrRelative() } #endif +void tst_QFileSystemEntry::isClean_data() +{ + QTest::addColumn("path"); + QTest::addColumn("isClean"); + + QTest::newRow("simple") << "foo" << true; + QTest::newRow("complex") << "/foo/bar/bz" << true; + QTest::newRow(".file") << "/foo/.file" << true; + QTest::newRow("..file") << "/foo/..file" << true; + QTest::newRow("...") << "/foo/.../bar" << true; + QTest::newRow("./") << "./" << false; + QTest::newRow("../") << "../" << false; + QTest::newRow(".") << "." << false; + QTest::newRow("..") << ".." << false; + QTest::newRow("/.") << "/." << false; + QTest::newRow("/..") << "/.." << false; + QTest::newRow("/../") << "foo/../bar" << false; + QTest::newRow("/./") << "foo/./bar" << false; + QTest::newRow("//") << "foo//bar" << false; +} + +void tst_QFileSystemEntry::isClean() +{ + QFETCH(QString, path); + QFETCH(bool, isClean); + + QFileSystemEntry fi(path); + QCOMPARE(fi.isClean(), isClean); +} + QTEST_MAIN(tst_QFileSystemEntry) #include -- cgit v1.2.3