Skip to content

fix: use path instead of filepath in FSLoader for fs.FS compatibility#376

Open
Yanhu007 wants to merge 1 commit intoflosch:masterfrom
Yanhu007:fix/fsloader-windows-path-separator
Open

fix: use path instead of filepath in FSLoader for fs.FS compatibility#376
Yanhu007 wants to merge 1 commit intoflosch:masterfrom
Yanhu007:fix/fsloader-windows-path-separator

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #373

Problem

FSLoader.Abs uses filepath.Join and filepath.Dir, which produce backslash-separated paths on Windows (e.g., templates\index.html). However, fs.FS implementations (including embed.FS) require forward-slash paths per the Go fs.FS specification. This causes "unable to resolve template" errors when using NewFSLoader on Windows.

Fix

Replace filepath.Join/filepath.Dir with path.Join/path.Dir in FSLoader.Abs. The path package always uses forward slashes, matching the fs.FS convention.

Only the FSLoader is changed — LocalFilesystemLoader correctly uses filepath since it operates on the OS filesystem.

FSLoader.Abs used filepath.Join and filepath.Dir which produce
backslash-separated paths on Windows. Since fs.FS (including
embed.FS) requires forward-slash paths per the Go specification,
this caused "unable to resolve template" errors on Windows.

Use path.Join and path.Dir instead, which always use forward
slashes regardless of platform.

Fixes flosch#373
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"unable to resolve template" error due to wrong seperator on filepaths

1 participant