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.
parent 95c99eb0
...@@ -310,8 +310,8 @@ func stripPathShortcuts(p string) string { ...@@ -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 = ""
} }
......
...@@ -173,6 +173,11 @@ func TestStripPathShortcuts(t *testing.T) { ...@@ -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 {
......
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