From 52f02c42e6a84a551b0f7eade38be62dd6c37cf2 Mon Sep 17 00:00:00 2001 From: Tomer Froumin Date: Thu, 11 Jan 2018 10:46:22 +0200 Subject: [PATCH] Fixed crash when path has multiple leading slashes --- pkg/kubectl/cmd/cp.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/kubectl/cmd/cp.go b/pkg/kubectl/cmd/cp.go index a5d67de3f96..150fe8ead3f 100644 --- a/pkg/kubectl/cmd/cp.go +++ b/pkg/kubectl/cmd/cp.go @@ -378,11 +378,8 @@ func untarAll(reader io.Reader, destFile, prefix string) error { } func getPrefix(file string) string { - if file[0] == '/' { - // tar strips the leading '/' if it's there, so we will too - return file[1:] - } - return file + // tar strips the leading '/' if it's there, so we will too + return strings.TrimLeft(file, "/") } func execute(f cmdutil.Factory, cmd *cobra.Command, options *ExecOptions) error {