diff --git a/libs/template/materialize.go b/libs/template/materialize.go index 7c9105b7..da0bc45d 100644 --- a/libs/template/materialize.go +++ b/libs/template/materialize.go @@ -104,6 +104,12 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st // If the given templateRoot matches func prepareBuiltinTemplates(templateRoot string, tempDir string) (string, error) { + // Check that `templateRoot` is a clean basename, i.e. `some_path` and not `./some_path` or "." + // Return early if that's not the case. + if templateRoot == "." || path.Base(templateRoot) != templateRoot { + return templateRoot, nil + } + _, err := fs.Stat(builtinTemplates, path.Join("templates", templateRoot)) if err != nil { // The given path doesn't appear to be using out built-in templates diff --git a/libs/template/renderer_test.go b/libs/template/renderer_test.go index d513eac8..8d0c2101 100644 --- a/libs/template/renderer_test.go +++ b/libs/template/renderer_test.go @@ -86,6 +86,18 @@ func assertBuiltinTemplateValid(t *testing.T, settings map[string]any, target st } } +func TestPrepareBuiltInTemplatesWithRelativePaths(t *testing.T) { + // CWD should not be resolved as a built in template + dir, err := prepareBuiltinTemplates(".", t.TempDir()) + assert.NoError(t, err) + assert.Equal(t, ".", dir) + + // relative path should not be resolved as a built in template + dir, err = prepareBuiltinTemplates("./default-python", t.TempDir()) + assert.NoError(t, err) + assert.Equal(t, "./default-python", dir) +} + func TestBuiltinTemplateValid(t *testing.T) { // Test option combinations options := []string{"yes", "no"}