Skip to content

Commit 6f99b50

Browse files
committed
Resolve template file path to an absolute path before reading it
1 parent b801018 commit 6f99b50

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/cmd/templates/templates.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,22 @@ func (tm *TemplateManager) GetTemplate(tpl string) (*template.Template, error) {
7676

7777
// Then check if it's a file path
7878
if isFilePath(tpl) {
79-
content, err := fsext.ReadFile(tm.fs, tpl)
79+
tplPath, err := filepath.Abs(tpl)
80+
if err != nil {
81+
return nil, fmt.Errorf("failed to get absolute path for template %s: %w", tpl, err)
82+
}
83+
84+
// Read the template content using the provided filesystem
85+
content, err := fsext.ReadFile(tm.fs, tplPath)
8086
if err != nil {
8187
return nil, fmt.Errorf("failed to read template file %s: %w", tpl, err)
8288
}
8389

84-
tmpl, err := template.New(filepath.Base(tpl)).Parse(string(content))
90+
tmpl, err := template.New(filepath.Base(tplPath)).Parse(string(content))
8591
if err != nil {
8692
return nil, fmt.Errorf("failed to parse template file %s: %w", tpl, err)
8793
}
94+
8895
return tmpl, nil
8996
}
9097

0 commit comments

Comments
 (0)