From d17ce325a64304f374ee4d1a20cf5334d35b8332 Mon Sep 17 00:00:00 2001 From: Srinidhi Kaushik Date: Tue, 16 Oct 2018 20:01:47 +0530 Subject: [PATCH] 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 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 {