aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/wintermute/utils/path_util.cpp6
-rw-r--r--test/engines/wintermute/path_utils.h14
2 files changed, 18 insertions, 2 deletions
diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp
index 60a07f0bf0..8518f8968f 100644
--- a/engines/wintermute/utils/path_util.cpp
+++ b/engines/wintermute/utils/path_util.cpp
@@ -71,7 +71,11 @@ bool PathUtil::hasTrailingSlash(const Common::String &path) {
Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
Common::String filename = getFileName(path);
- return Common::String(path.c_str(), path.size() - filename.size());
+ if (hasTrailingSlash(newPath)) {
+ return path;
+ } else {
+ return Common::String(path.c_str(), path.size() - filename.size());
+ }
}
//////////////////////////////////////////////////////////////////////////
diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h
index 3cacf47fd9..26f3404396 100644
--- a/test/engines/wintermute/path_utils.h
+++ b/test/engines/wintermute/path_utils.h
@@ -23,6 +23,8 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
const Common::String mixedSlashesPath2;
const Common::String unixRelativePath;
const Common::String windowsRelativePath;
+ const Common::String unixDirPath;
+ const Common::String windowsDirPath;
PathUtilTestSuite () :
unixPath("/some/file.ext"),
unixCapPath("/SOME/FILE.EXT"),
@@ -34,7 +36,9 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"),
mixedSlashesPath2("/pretty\\weird/indeed.txt"),
unixRelativePath("some/file.ext"),
- windowsRelativePath("some\\file.ext")
+ windowsRelativePath("some\\file.ext"),
+ unixDirPath("/some/dir/"),
+ windowsDirPath("C:\\some\\dir\\")
{}
void test_getdirectoryname() {
TS_ASSERT_EQUALS(
@@ -57,6 +61,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Wintermute::PathUtil::getDirectoryName(emptyString),
Common::String("")
);
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getDirectoryName(unixDirPath),
+ Common::String("/some/dir/")
+ );
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getDirectoryName(windowsDirPath),
+ Common::String("C:\\some\\dir\\")
+ );
}
void test_getfilename() {