Commit dbb6723c authored by mmenke's avatar mmenke Committed by Commit bot

Fix a pair of bugs in UNIX->VMS path conversion.

In particular:
* Fix conversion of UNIX file name "/////file" and "////" as a UNIX
  path.  Both of these were broken, due to the same bug.
* Remove a DCHECK that would trigger on "//" as a file name. It's a
  valid UNIX path, if not a file name, and can still be passed through
  the file name conversion code.  Since there's no code to prevent
  that from happening, and the conversion code handles "/", the DCHECK
  made no sense.

BUG=675111

Review-Url: https://codereview.chromium.org/2610973002
Cr-Commit-Position: refs/heads/master@{#441423}
parent bead6d12
......@@ -45,12 +45,12 @@ std::string FtpUtil::UnixFilePathToVMS(const std::string& unix_path) {
// It's an absolute path.
if (tokens.empty()) {
DCHECK_EQ(1U, unix_path.length());
// It's just "/" or a series of slashes, which all mean the same thing.
return "[]";
}
if (tokens.size() == 1)
return unix_path.substr(1); // Drop the leading slash.
return tokens.front(); // Return without leading slashes.
std::string result(tokens[0] + ":[");
if (tokens.size() == 2) {
......
......@@ -34,6 +34,11 @@ TEST(FtpUtilTest, UnixFilePathToVMS) {
{ "a/b", "[.a]b" },
{ "a/b/c", "[.a.b]c" },
{ "a/b/c/d", "[.a.b.c]d" },
// Extra slashes shouldn't matter.
{ "/////", "[]" },
{ "/////a", "a" },
{ "//a//b///c", "a:[b]c" },
{ "a//b///c", "[.a.b]c" },
};
for (size_t i = 0; i < arraysize(kTestCases); i++) {
EXPECT_EQ(kTestCases[i].expected_output,
......@@ -47,26 +52,30 @@ TEST(FtpUtilTest, UnixDirectoryPathToVMS) {
const char* input;
const char* expected_output;
} kTestCases[] = {
{ "", "" },
{ "/", "" },
{ "/a", "a:[000000]" },
{ "/a/", "a:[000000]" },
{ "/a/b", "a:[b]" },
{ "/a/b/", "a:[b]" },
{ "/a/b/c", "a:[b.c]" },
{ "/a/b/c/", "a:[b.c]" },
{ "/a/b/c/d", "a:[b.c.d]" },
{ "/a/b/c/d/", "a:[b.c.d]" },
{ "/a/b/c/d/e", "a:[b.c.d.e]" },
{ "/a/b/c/d/e/", "a:[b.c.d.e]" },
{ "a", "[.a]" },
{ "a/", "[.a]" },
{ "a/b", "[.a.b]" },
{ "a/b/", "[.a.b]" },
{ "a/b/c", "[.a.b.c]" },
{ "a/b/c/", "[.a.b.c]" },
{ "a/b/c/d", "[.a.b.c.d]" },
{ "a/b/c/d/", "[.a.b.c.d]" },
{ "", "" },
{ "/", "" },
{ "/a", "a:[000000]" },
{ "/a/", "a:[000000]" },
{ "/a/b", "a:[b]" },
{ "/a/b/", "a:[b]" },
{ "/a/b/c", "a:[b.c]" },
{ "/a/b/c/", "a:[b.c]" },
{ "/a/b/c/d", "a:[b.c.d]" },
{ "/a/b/c/d/", "a:[b.c.d]" },
{ "/a/b/c/d/e", "a:[b.c.d.e]" },
{ "/a/b/c/d/e/", "a:[b.c.d.e]" },
{ "a", "[.a]" },
{ "a/", "[.a]" },
{ "a/b", "[.a.b]" },
{ "a/b/", "[.a.b]" },
{ "a/b/c", "[.a.b.c]" },
{ "a/b/c/", "[.a.b.c]" },
{ "a/b/c/d", "[.a.b.c.d]" },
{ "a/b/c/d/", "[.a.b.c.d]" },
// Extra slashes shouldn't matter.
{ "/////", "" },
{ "//a//b///c//", "a:[b.c]" },
{ "a//b///c//", "[.a.b.c]" },
};
for (size_t i = 0; i < arraysize(kTestCases); i++) {
EXPECT_EQ(kTestCases[i].expected_output,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment