Optimize out empty path components

filepath.Join("foo", "") returns a newly allocated copy of "foo",
while filepath.Join("foo") does not.  Strip out any empty path
components before calling filepath.Join.

Test: TestValidatePath
Change-Id: Ib47dbcd9d6463809acfe260dfd9af87ea280b4de
This commit is contained in:
Colin Cross
2023-10-24 14:17:03 -07:00
parent 9ae2999dab
commit bf9ed3fba2
2 changed files with 34 additions and 2 deletions

View File

@@ -36,6 +36,22 @@ var commonValidatePathTestCases = []strsTestCase{
in: []string{""},
out: "",
},
{
in: []string{"", ""},
out: "",
},
{
in: []string{"a", ""},
out: "a",
},
{
in: []string{"", "a"},
out: "a",
},
{
in: []string{"", "a", ""},
out: "a",
},
{
in: []string{"a/b"},
out: "a/b",