From d67cba4b29cb5586471e207ceea83f9aa473833c Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sat, 31 Jan 2026 13:19:05 +0100 Subject: [PATCH] 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 --- compiler.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler.go b/compiler.go index 6f4985e5..733d5f3b 100644 --- a/compiler.go +++ b/compiler.go @@ -198,18 +198,21 @@ func (c *Compiler) ResetCache() { } func (c *Compiler) getSpecialVars(t *ast.Task, call *Call) (map[string]string, error) { + // Use filepath.ToSlash for all paths to ensure consistent forward slashes + // across platforms. This prevents issues with backslashes being interpreted + // as escape sequences when paths are used in shell commands on Windows. allVars := map[string]string{ - "TASK_EXE": os.Args[0], - "ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint), - "ROOT_DIR": c.Dir, - "USER_WORKING_DIR": c.UserWorkingDir, + "TASK_EXE": filepath.ToSlash(os.Args[0]), + "ROOT_TASKFILE": filepath.ToSlash(filepathext.SmartJoin(c.Dir, c.Entrypoint)), + "ROOT_DIR": filepath.ToSlash(c.Dir), + "USER_WORKING_DIR": filepath.ToSlash(c.UserWorkingDir), "TASK_VERSION": version.GetVersion(), } if t != nil { allVars["TASK"] = t.Task - allVars["TASK_DIR"] = filepathext.SmartJoin(c.Dir, t.Dir) - allVars["TASKFILE"] = t.Location.Taskfile - allVars["TASKFILE_DIR"] = filepath.Dir(t.Location.Taskfile) + allVars["TASK_DIR"] = filepath.ToSlash(filepathext.SmartJoin(c.Dir, t.Dir)) + allVars["TASKFILE"] = filepath.ToSlash(t.Location.Taskfile) + allVars["TASKFILE_DIR"] = filepath.ToSlash(filepath.Dir(t.Location.Taskfile)) } else { allVars["TASK"] = "" allVars["TASK_DIR"] = ""