Skip to content

Commit 3e804a2

Browse files
committed
fix: restore forward slashes for special path variables
The test proved that normalizing only in tests is not sufficient. The production code must use forward slashes to: 1. Prevent escape sequence issues (\a, \t interpreted as bell, tab) 2. Ensure consistent behavior across platforms 3. Allow portable Taskfiles that work on all OSes
1 parent 91e2e97 commit 3e804a2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

compiler.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,21 @@ func (c *Compiler) ResetCache() {
198198
}
199199

200200
func (c *Compiler) getSpecialVars(t *ast.Task, call *Call) (map[string]string, error) {
201+
// Use filepath.ToSlash for all paths to ensure consistent forward slashes
202+
// across platforms. This prevents issues with backslashes being interpreted
203+
// as escape sequences when paths are used in shell commands on Windows.
201204
allVars := map[string]string{
202-
"TASK_EXE": os.Args[0],
203-
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
204-
"ROOT_DIR": c.Dir,
205-
"USER_WORKING_DIR": c.UserWorkingDir,
205+
"TASK_EXE": filepath.ToSlash(os.Args[0]),
206+
"ROOT_TASKFILE": filepath.ToSlash(filepathext.SmartJoin(c.Dir, c.Entrypoint)),
207+
"ROOT_DIR": filepath.ToSlash(c.Dir),
208+
"USER_WORKING_DIR": filepath.ToSlash(c.UserWorkingDir),
206209
"TASK_VERSION": version.GetVersion(),
207210
}
208211
if t != nil {
209212
allVars["TASK"] = t.Task
210-
allVars["TASK_DIR"] = filepathext.SmartJoin(c.Dir, t.Dir)
211-
allVars["TASKFILE"] = t.Location.Taskfile
212-
allVars["TASKFILE_DIR"] = filepath.Dir(t.Location.Taskfile)
213+
allVars["TASK_DIR"] = filepath.ToSlash(filepathext.SmartJoin(c.Dir, t.Dir))
214+
allVars["TASKFILE"] = filepath.ToSlash(t.Location.Taskfile)
215+
allVars["TASKFILE_DIR"] = filepath.ToSlash(filepath.Dir(t.Location.Taskfile))
213216
} else {
214217
allVars["TASK"] = ""
215218
allVars["TASK_DIR"] = ""

0 commit comments

Comments
 (0)