diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 5ce3e673055e3..d6a47237ef313 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -1013,7 +1013,7 @@ std::string CUtil::ValidatePath(const std::string &path, bool bFixDoubleSlashes for (size_t x = 1; x < result.size() - 1; x++) { if (result[x] == '\\' && result[x+1] == '\\') - result.erase(x); + result.erase(x, 1); } } } @@ -1031,7 +1031,7 @@ std::string CUtil::ValidatePath(const std::string &path, bool bFixDoubleSlashes for (size_t x = 2; x < result.size() - 1; x++) { if ( result[x] == '/' && result[x + 1] == '/' && !(result[x - 1] == ':' || (result[x - 1] == '/' && result[x - 2] == ':')) ) - result.erase(x); + result.erase(x, 1); } } } diff --git a/xbmc/test/TestUtil.cpp b/xbmc/test/TestUtil.cpp index 3df3fc7fd512a..bab3a7516ee96 100644 --- a/xbmc/test/TestUtil.cpp +++ b/xbmc/test/TestUtil.cpp @@ -102,3 +102,27 @@ TEST(TestUtil, MakeShortenPath) EXPECT_EQ(true, CUtil::MakeShortenPath("//test//string/is/long/and/very//much/so", result, 30)); EXPECT_EQ("/../../../../../so", result); } + +TEST(TestUtil, ValidatePath) +{ + std::string path; +#ifdef TARGET_WINDOWS + path = "C:/foo/bar/"; + EXPECT_EQ(CUtil::ValidatePath(path), "C:\\foo\\bar\\"); + path = "C:\\\\foo\\\\bar\\"; + EXPECT_EQ(CUtil::ValidatePath(path, true), "C:\\foo\\bar\\"); + path = "\\\\foo\\\\bar\\"; + EXPECT_EQ(CUtil::ValidatePath(path, true), "\\\\foo\\bar\\"); +#else + path = "\\foo\\bar\\"; + EXPECT_EQ(CUtil::ValidatePath(path), "/foo/bar/"); + path = "/foo//bar/"; + EXPECT_EQ(CUtil::ValidatePath(path, true), "/foo/bar/"); +#endif + path = "smb://foo/bar/"; + EXPECT_EQ(CUtil::ValidatePath(path), "smb://foo/bar/"); + path = "smb://foo//bar/"; + EXPECT_EQ(CUtil::ValidatePath(path, true), "smb://foo/bar/"); + path = "smb:\\\\foo\\\\bar\\"; + EXPECT_EQ(CUtil::ValidatePath(path, true), "smb://foo/bar/"); +}