diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index a3b62fdeebd..93366db0aea 100644 --- a/pkg/kubectl/cmd/cp/cp.go +++ b/pkg/kubectl/cmd/cp/cp.go @@ -315,8 +315,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 1764f8a55b3..b8a14dfc540 100644 --- a/pkg/kubectl/cmd/cp/cp_test.go +++ b/pkg/kubectl/cmd/cp/cp_test.go @@ -175,6 +175,11 @@ func TestStripPathShortcuts(t *testing.T) { input: "...foo", expected: "...foo", }, + { + name: "test root directory", + input: "/", + expected: "", + }, } for _, test := range tests {