From d17ce325a64304f374ee4d1a20cf5334d35b8332 Mon Sep 17 00:00:00 2001 From: Srinidhi Kaushik Date: Tue, 16 Oct 2018 20:01:47 +0530 Subject: [PATCH 1/2] 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. --- pkg/kubectl/cmd/cp/cp.go | 4 ++-- pkg/kubectl/cmd/cp/cp_test.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index 8b4817d6749..edca8614bdb 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 f1e7f38f1a1..937ff522d3a 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 { From 00720ba51d9320183d73d128bcdfd404bf594427 Mon Sep 17 00:00:00 2001 From: Srinidhi Kaushik Date: Tue, 16 Oct 2018 21:31:59 +0530 Subject: [PATCH 2/2] Fix `gofmt' errors. --- pkg/kubectl/cmd/cp/cp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index edca8614bdb..92fd0eb5095 100644 --- a/pkg/kubectl/cmd/cp/cp.go +++ b/pkg/kubectl/cmd/cp/cp.go @@ -311,7 +311,7 @@ func stripPathShortcuts(p string) string { } // trim leftover {".", ".."} - if (newPath == "." || newPath == "..") { + if newPath == "." || newPath == ".." { newPath = "" }