Common: Fix bug in lastPathComponent.

Prior to this change lastPathComponent would not create a correct result,
when the input of lastPathComponent did not contain a single separator.

I also added a test case for this in our unit tests.

svn-id: r52123
This commit is contained in:
Johannes Schickel 2010-08-16 16:01:31 +00:00
parent c284e78cc0
commit 7b51537be2
2 changed files with 3 additions and 1 deletions

View File

@ -626,7 +626,7 @@ Common::String lastPathComponent(const Common::String &path, const char sep) {
// Now scan the whole component
const char *first = last - 1;
while (first >= str && *first != sep)
while (first > str && *first != sep)
--first;
if (*first == sep)

View File

@ -266,6 +266,8 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(Common::lastPathComponent("foo/./bar", '/'), "bar");
TS_ASSERT_EQUALS(Common::lastPathComponent("foo//./bar//", '/'), "bar");
TS_ASSERT_EQUALS(Common::lastPathComponent("foo//.bar//", '/'), ".bar");
TS_ASSERT_EQUALS(Common::lastPathComponent("foo", '/'), "foo");
}
void test_normalizePath() {