diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index 8b4817d674..edca8614bd 100644 --- a/pkg/kubectl/cmd/cp/cp.go +++ b/pkg/kubectl/cmd/cp/cp.go @@ -310,8 +310,8 @@ func stripPathShortcuts(p string) string { trimmed = strings.TrimPrefix(newPath, "../") } - // trim leftover ".." - if newPath == ".." { + // trim leftover {".", ".."} + if (newPath == "." || newPath == "..") { newPath = "" } diff --git a/pkg/kubectl/cmd/cp/cp_test.go b/pkg/kubectl/cmd/cp/cp_test.go index f1e7f38f1a..937ff522d3 100644 --- a/pkg/kubectl/cmd/cp/cp_test.go +++ b/pkg/kubectl/cmd/cp/cp_test.go @@ -173,6 +173,11 @@ func TestStripPathShortcuts(t *testing.T) { input: "...foo", expected: "...foo", }, + { + name: "test root directory", + input: "/", + expected: "", + }, } for _, test := range tests {