From 7b51537be2341b62795c308c140faca387fa04e6 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 16 Aug 2010 16:01:31 +0000 Subject: [PATCH] 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 --- common/str.cpp | 2 +- test/common/str.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/str.cpp b/common/str.cpp index 744ba46ec7b..2a0130dbe45 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -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) diff --git a/test/common/str.h b/test/common/str.h index 6581c37cdbb..e1f2b39578a 100644 --- a/test/common/str.h +++ b/test/common/str.h @@ -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() {