summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-06-04 16:02:06 +0200
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-06-24 15:43:58 +0000
commitec8c1dcf147ac71ea3c0105d67c2575ab733d348 (patch)
treec7e9f264ee899779d154e3bb0afc3871f61c60d4
parent0e41a58fb8f15a9a0790db2f33efe32d3c227bc2 (diff)
Make QDir::relativeFilePath() return "." for a path to itself.
The rationale being that the empty string is not a valid path component. [ChangeLog][QtCore][QDir] QDir::relativeFilePath() now returns "." instead of an empty string if the given path is the same as the directory. Change-Id: Ibcf31904b2ae5edf5639d4c2e5ba234365d347fd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r--src/corelib/io/qdir.cpp2
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp11
-rw-r--r--tests/auto/tools/qmakelib/evaltest.cpp4
3 files changed, 11 insertions, 6 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 9b1ec3917a..6687ff846c 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -777,6 +777,8 @@ QString QDir::relativeFilePath(const QString &fileName) const
result += QLatin1Char('/');
}
+ if (result.isEmpty())
+ return QLatin1String(".");
return result;
}
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index e8a7105f6e..45289df398 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -1366,6 +1366,9 @@ void tst_QDir::relativeFilePath_data()
QTest::newRow("11") << "" << "" << "";
+ QTest::newRow("same path 1") << "/tmp" << "/tmp" << ".";
+ QTest::newRow("same path 2") << "//tmp" << "/tmp/" << ".";
+
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
QTest::newRow("12") << "C:/foo/bar" << "ding" << "ding";
QTest::newRow("13") << "C:/foo/bar" << "C:/ding/dong" << "../../ding/dong";
@@ -1373,10 +1376,10 @@ void tst_QDir::relativeFilePath_data()
QTest::newRow("15") << "C:/foo/bar" << "D:/ding/dong" << "D:/ding/dong";
QTest::newRow("16") << "C:" << "C:/ding/dong" << "ding/dong";
QTest::newRow("17") << "C:/" << "C:/ding/dong" << "ding/dong";
- QTest::newRow("18") << "C:" << "C:" << "";
- QTest::newRow("19") << "C:/" << "C:" << "";
- QTest::newRow("20") << "C:" << "C:/" << "";
- QTest::newRow("21") << "C:/" << "C:/" << "";
+ QTest::newRow("18") << "C:" << "C:" << ".";
+ QTest::newRow("19") << "C:/" << "C:" << ".";
+ QTest::newRow("20") << "C:" << "C:/" << ".";
+ QTest::newRow("21") << "C:/" << "C:/" << ".";
QTest::newRow("22") << "C:" << "C:file.txt" << "file.txt";
QTest::newRow("23") << "C:/" << "C:file.txt" << "file.txt";
QTest::newRow("24") << "C:" << "C:/file.txt" << "file.txt";
diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp
index fab2cdce17..bed4c792a1 100644
--- a/tests/auto/tools/qmakelib/evaltest.cpp
+++ b/tests/auto/tools/qmakelib/evaltest.cpp
@@ -1356,7 +1356,7 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
QTest::newRow("$$relative_path(): relative file to empty")
<< "VAR = $$relative_path(dir/..)"
- << "VAR ="
+ << "VAR = ."
<< ""
<< true;
@@ -1368,7 +1368,7 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
QTest::newRow("$$relative_path(): empty file & path")
<< "VAR = $$relative_path('', /root/sub)"
- << "VAR ="
+ << "VAR = ."
<< ""
<< true;