From f4418920fb67e75bb666630e19d698a36424ccda Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 11 Feb 2022 17:58:45 +0100 Subject: [PATCH 1/3] Adds support for dot-prefixed paths in git - in `flux bootstrap` and `flux create kustomization` etc. - E.g. for example `--path=.flux` should work now - Previous behaviour is to strip off any leading "." and leave you with "./flux" in the kustomizations / folder structure generated by `flux bootstrap` Signed-off-by: Simon Howe --- internal/flags/safe_relative_path.go | 5 ++++- internal/flags/safe_relative_path_test.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/flags/safe_relative_path.go b/internal/flags/safe_relative_path.go index 4a5f78df..dfd3b9ea 100644 --- a/internal/flags/safe_relative_path.go +++ b/internal/flags/safe_relative_path.go @@ -41,7 +41,10 @@ func (p *SafeRelativePath) Set(str string) error { return fmt.Errorf("invalid relative path '%s': %w", cleanP, err) } // NB: required, as a secure join of "./" will result in "." - cleanP = fmt.Sprintf("./%s", strings.TrimPrefix(cleanP, ".")) + if cleanP == "." { + cleanP = "" + } + cleanP = fmt.Sprintf("./%s", cleanP) *p = SafeRelativePath(cleanP) return nil } diff --git a/internal/flags/safe_relative_path_test.go b/internal/flags/safe_relative_path_test.go index 325bd658..5c74ca28 100644 --- a/internal/flags/safe_relative_path_test.go +++ b/internal/flags/safe_relative_path_test.go @@ -37,6 +37,10 @@ func TestRelativePath_Set(t *testing.T) { {"traversing absolute path", "/foo/../bar", "./bar", false}, {"traversing overflowing absolute path", "/foo/../../../bar", "./bar", false}, {"empty", "", "./", false}, + {"relative empty path", "./", "./", false}, + {"double relative empty path", "././", "./", false}, + {"dot path", ".foo", "./.foo", false}, + {"relative dot path", "./.foo", "./.foo", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From aac07f03d867e058af257b8b914ebd4ba4f3d1ec Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Mon, 14 Feb 2022 10:44:56 +0100 Subject: [PATCH 2/3] Adds test for using dot to represent pwd Signed-off-by: Simon Howe --- internal/flags/safe_relative_path_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/flags/safe_relative_path_test.go b/internal/flags/safe_relative_path_test.go index 5c74ca28..86ba64da 100644 --- a/internal/flags/safe_relative_path_test.go +++ b/internal/flags/safe_relative_path_test.go @@ -41,6 +41,7 @@ func TestRelativePath_Set(t *testing.T) { {"double relative empty path", "././", "./", false}, {"dot path", ".foo", "./.foo", false}, {"relative dot path", "./.foo", "./.foo", false}, + {"current directory", ".", "./", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 23c4c2f1aa7b5c0a55374a9185bcf69531694838 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Mon, 14 Feb 2022 10:51:20 +0100 Subject: [PATCH 3/3] Adds test for parent directory Signed-off-by: Simon Howe --- internal/flags/safe_relative_path_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/flags/safe_relative_path_test.go b/internal/flags/safe_relative_path_test.go index 86ba64da..a9d5f3fe 100644 --- a/internal/flags/safe_relative_path_test.go +++ b/internal/flags/safe_relative_path_test.go @@ -42,6 +42,8 @@ func TestRelativePath_Set(t *testing.T) { {"dot path", ".foo", "./.foo", false}, {"relative dot path", "./.foo", "./.foo", false}, {"current directory", ".", "./", false}, + {"parent directory", "..", "./", false}, + {"parent directory more qualified", "./..", "./", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {