Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUtil::ValidatePath fix double (back)slash check #15499

Merged
merged 2 commits into from Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions xbmc/Util.cpp
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions xbmc/test/TestUtil.cpp
Expand Up @@ -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/");
}