From a84a92a0c4859c285a182ce41536d8865496f11a Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Fri, 15 Nov 2024 10:09:48 +0100 Subject: [PATCH 1/3] Do not prepend paths starting with ~ or variable reference --- bundle/config/mutator/prepend_workspace_prefix.go | 2 ++ bundle/config/mutator/prepend_workspace_prefix_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index de71bf7fd8..f6439022d4 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -24,6 +24,8 @@ func (m *prependWorkspacePrefix) Name() string { var skipPrefixes = []string{ "/Workspace/", "/Volumes/", + "${", // Skipping all the paths starting with variable reference, such as ${workspace.root_path} + "~/", // Skipping paths starting with a home folder } func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { diff --git a/bundle/config/mutator/prepend_workspace_prefix_test.go b/bundle/config/mutator/prepend_workspace_prefix_test.go index 6fbadec56b..31393e6bd8 100644 --- a/bundle/config/mutator/prepend_workspace_prefix_test.go +++ b/bundle/config/mutator/prepend_workspace_prefix_test.go @@ -31,6 +31,14 @@ func TestPrependWorkspacePrefix(t *testing.T) { path: "/Volumes/Users/test", expected: "/Volumes/Users/test", }, + { + path: "~/test", + expected: "~/test", + }, + { + path: "${workspace.file_path}/test", + expected: "${workspace.file_path}/test", + }, } for _, tc := range testCases { From e82f5a5b1c42eb772b423d553bef163b89589df6 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Fri, 15 Nov 2024 11:26:22 +0100 Subject: [PATCH 2/3] fix --- bundle/config/mutator/prepend_workspace_prefix.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index f6439022d4..a3e3388ecc 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -24,8 +24,6 @@ func (m *prependWorkspacePrefix) Name() string { var skipPrefixes = []string{ "/Workspace/", "/Volumes/", - "${", // Skipping all the paths starting with variable reference, such as ${workspace.root_path} - "~/", // Skipping paths starting with a home folder } func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { @@ -47,6 +45,11 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di } for _, prefix := range skipPrefixes { + // Skip prefixing if the path does not start with /, it might be variable reference or smth else. + if !strings.HasPrefix(path, "/") { + return pv, nil + } + if strings.HasPrefix(path, prefix) { return pv, nil } From 66afae272b22b7a95c73fc8f85da19dfcdf591e5 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Fri, 15 Nov 2024 14:48:38 +0100 Subject: [PATCH 3/3] fix --- bundle/config/mutator/prepend_workspace_prefix.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index a3e3388ecc..e0be2572d5 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -44,12 +44,12 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di return dyn.InvalidValue, fmt.Errorf("expected string, got %s", v.Kind()) } - for _, prefix := range skipPrefixes { - // Skip prefixing if the path does not start with /, it might be variable reference or smth else. - if !strings.HasPrefix(path, "/") { - return pv, nil - } + // Skip prefixing if the path does not start with /, it might be variable reference or smth else. + if !strings.HasPrefix(path, "/") { + return pv, nil + } + for _, prefix := range skipPrefixes { if strings.HasPrefix(path, prefix) { return pv, nil }