Fix local copy path for `kubectl cp'.

Adds an extra check condition for "." in stripPathShortcuts
so that an empty string is returned, and the correct prefix
index is used untarAll when generating path names.

Resolves: #69804.
This commit is contained in:
Srinidhi Kaushik
2018-10-16 20:01:47 +05:30
parent 95c99eb052
commit d17ce325a6
2 changed files with 7 additions and 2 deletions

View File

@@ -310,8 +310,8 @@ func stripPathShortcuts(p string) string {
trimmed = strings.TrimPrefix(newPath, "../") trimmed = strings.TrimPrefix(newPath, "../")
} }
// trim leftover ".." // trim leftover {".", ".."}
if newPath == ".." { if (newPath == "." || newPath == "..") {
newPath = "" newPath = ""
} }

View File

@@ -173,6 +173,11 @@ func TestStripPathShortcuts(t *testing.T) {
input: "...foo", input: "...foo",
expected: "...foo", expected: "...foo",
}, },
{
name: "test root directory",
input: "/",
expected: "",
},
} }
for _, test := range tests { for _, test := range tests {