[Scummvm-git-logs] scummvm master -> 0a65e3724dfdef3871c7771752aa5affeece5288

lephilousophe noreply at scummvm.org
Sat Jan 31 13:12:33 UTC 2026


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
0a65e3724d COMMON: Don't escape base name if it wasn't escaped


Commit: 0a65e3724dfdef3871c7771752aa5affeece5288
    https://github.com/scummvm/scummvm/commit/0a65e3724dfdef3871c7771752aa5affeece5288
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2026-01-31T14:12:12+01:00

Commit Message:
COMMON: Don't escape base name if it wasn't escaped

And add a testcase for it.

Changed paths:
    common/path.cpp
    test/common/path.h


diff --git a/common/path.cpp b/common/path.cpp
index 658744b03a5..dd69c348074 100644
--- a/common/path.cpp
+++ b/common/path.cpp
@@ -384,6 +384,7 @@ String Path::baseName() const {
 		return String();
 	}
 
+	bool escaped = isEscaped();
 	size_t last = _str.size();
 	if (isSeparatorTerminated()) {
 		last--;
@@ -396,12 +397,16 @@ String Path::baseName() const {
 
 	if (separatorPos != String::npos) {
 		begin += separatorPos + 1;
-	} else if (isEscaped()) {
+	} else if (escaped) {
 		// unescape uses the real start, not the escape marker
 		begin++;
 	}
 	end += last;
 
+	if (!escaped) {
+		return String(begin, end);
+	}
+
 	return unescape(kNoSeparator, begin, end);
 }
 
diff --git a/test/common/path.h b/test/common/path.h
index bbf2607f551..39b5299401d 100644
--- a/test/common/path.h
+++ b/test/common/path.h
@@ -8,6 +8,7 @@
 static const char *TEST_PATH = "parent/dir/file.txt";
 static const char *TEST_ESCAPED1_PATH = "|parent/dir/file.txt";
 static const char *TEST_ESCAPED2_PATH = "par/ent\\dir\\file.txt";
+static const char *TEST_ESCAPED3_PATH = "parent\\dir\\fi|le.txt";
 static const char *TEST_BS_PATH = "parent\\dir\\file.txt";
 
 class PathTestSuite : public CxxTest::TestSuite
@@ -30,8 +31,12 @@ class PathTestSuite : public CxxTest::TestSuite
 		Common::Path p4(TEST_ESCAPED2_PATH, '\\');
 		TS_ASSERT_EQUALS(p4.toString('\\'), TEST_ESCAPED2_PATH);
 
-		Common::Path p5(TEST_BS_PATH, '\\');
-		TS_ASSERT_EQUALS(p5.toString('\\'), TEST_BS_PATH);
+		Common::Path p5(TEST_ESCAPED3_PATH, '\\');
+		TS_ASSERT_EQUALS(p5.toString('\\'), TEST_ESCAPED3_PATH);
+		TS_ASSERT_EQUALS(p5.baseName(), "fi|le.txt");
+
+		Common::Path p6(TEST_BS_PATH, '\\');
+		TS_ASSERT_EQUALS(p6.toString('\\'), TEST_BS_PATH);
 
 #ifndef RELEASE_BUILD
 		Common::Path::_shownSeparatorCollisionWarning = false;
@@ -47,7 +52,7 @@ class PathTestSuite : public CxxTest::TestSuite
 		TS_ASSERT_EQUALS(Common::Path::_shownSeparatorCollisionWarning, true);
 
 		Common::Path::_shownSeparatorCollisionWarning = false;
-		TS_ASSERT_EQUALS(p5.toString('i'), "parentidirifile.txt");
+		TS_ASSERT_EQUALS(p6.toString('i'), "parentidirifile.txt");
 		TS_ASSERT_EQUALS(Common::Path::_shownSeparatorCollisionWarning, true);
 #endif
 	}




More information about the Scummvm-git-logs mailing list