summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-09-01 14:04:33 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-09-02 12:38:57 (GMT)
commitddf5a09d469a1ded5490cffe54e0013a0d5ba347 (patch)
tree656e7a7abaacd551f554bf2326dba20276eb194d /tests
parentca34cc75294e0d2a8bc491a2c679fe8a69cd0408 (diff)
downloadQt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.zip
Qt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.tar.gz
Qt-ddf5a09d469a1ded5490cffe54e0013a0d5ba347.tar.bz2
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 <qt_sanity_bot@ovi.com> Reviewed-by: Prasanth Ullattil <prasanth.ullattil@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qdir/tst_qdir.cpp13
-rw-r--r--tests/auto/qfilesystementry/tst_qfilesystementry.cpp32
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
index 419eaae..7e5ec79 100644
--- a/tests/auto/qdir/tst_qdir.cpp
+++ b/tests/auto/qdir/tst_qdir.cpp
@@ -1133,6 +1133,11 @@ void tst_QDir::absolutePath_data()
QTest::newRow("4") << "c:/machine/share/dir1" << "c:/machine/share/dir1";
QTest::newRow("5") << "c:\\machine\\share\\dir1" << "c:/machine/share/dir1";
#endif
+ //test dirty paths are cleaned (QTBUG-19995)
+ QTest::newRow("/home/qt/.") << QDir::rootPath() + "home/qt/." << QDir::rootPath() + "home/qt";
+ QTest::newRow("/system/data/../config") << QDir::rootPath() + "system/data/../config" << QDir::rootPath() + "system/config";
+ QTest::newRow("//home//qt/") << QDir::rootPath() + "/home//qt/" << QDir::rootPath() + "home/qt";
+ QTest::newRow("foo/../bar") << "foo/../bar" << QDir::currentPath() + "/bar";
QTest::newRow("resource") << ":/prefix/foo.bar" << ":/prefix/foo.bar";
}
@@ -1942,6 +1947,14 @@ void tst_QDir::equalityOperator_data()
<< "./entrylist" << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< true;
+ QTest::newRow("QTBUG-20495") << QDir::currentPath() + "/entrylist/.." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << "." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << true;
+
+ QTest::newRow("QTBUG-20495-root") << QDir::rootPath() + "tmp/.." << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << QDir::rootPath() << "*.cpp" << int(QDir::Name) << int(QDir::Files)
+ << true;
+
QTest::newRow("diff-filters") << SRCDIR << "*.cpp" << int(QDir::Name) << int(QDir::Files)
<< SRCDIR << "*.cpp" << int(QDir::Name) << int(QDir::Dirs)
<< false;
diff --git a/tests/auto/qfilesystementry/tst_qfilesystementry.cpp b/tests/auto/qfilesystementry/tst_qfilesystementry.cpp
index 016bcbf..2daabee 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<QString>("path");
+ QTest::addColumn<bool>("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 <tst_qfilesystementry.moc>