Skip to content

fix: only treat special dirs as absolute when used as template expressions (Closes #3021) - #3105

Open
pethapixels-create wants to merge 2 commits into
go-task:mainfrom
pethapixels-create:fix/smartjoin-special-dir-substring
Open

pethapixels-create wants to merge 2 commits into
go-task:mainfrom
pethapixels-create:fix/smartjoin-special-dir-substring

Conversation

@pethapixels-create

Copy link
Copy Markdown

What

Fixes SmartJoin/IsAbs so that ordinary relative paths whose names merely contain a special variable name (e.g. project.ROOT_DIR/file.txt) are no longer treated as absolute/special paths.

Why

isSpecialDir matched the special variable names (.ROOT_DIR, .TASKFILE_DIR, .USER_WORKING_DIR) as bare substrings. Any relative path containing one of these strings anywhere in it was incorrectly considered absolute, causing SmartJoin to return it unchanged instead of joining it with the base directory. See #3021.

How

Special variables are only ever absolute when they appear as an actual template expression, e.g. {{.ROOT_DIR}}. The check now looks for the {{ + name prefix instead of a bare substring, so real template expressions still resolve as absolute while ordinary relative paths are joined normally.

Tests

Added table-driven tests in internal/filepathext/filepathext_test.go covering IsAbs and SmartJoin, including regression cases for relative paths containing .ROOT_DIR, .TASKFILE_DIR, and .USER_WORKING_DIR.

go build ./...        # passes
go test ./internal/filepathext/... ./internal/fsext/... ./internal/fingerprint/... -count=1   # all ok

Closes #3021

pethapixels-create and others added 2 commits November 22, 2026 09:15
…sions (Closes go-task#3021)

isSpecialDir previously matched special variable names (e.g. .ROOT_DIR)
as bare substrings, so ordinary relative paths whose names merely contain
one of these strings (e.g. "project.ROOT_DIR/file.txt") were incorrectly
treated as absolute and skipped the base-dir join in SmartJoin.

Match only actual template expressions ("{{.ROOT_DIR}}" or
"{{ .ROOT_DIR }}"), allowing optional whitespace after "{{" as Go
templates do. Adds table-driven regression tests for all three special
vars plus the spaced-template form.
@pethapixels-create

Copy link
Copy Markdown
Author

CI/triage note: Branch is MERGEABLE with no required checks gating this path. Root cause: isSpecialDir matched {{.ROOT_DIR}}-style names (.ROOT_DIR, .TASKFILE_DIR, .USER_WORKING_DIR) as bare substrings, so any relative path merely containing one (e.g. project.ROOT_DIR/file.txt) was wrongly treated as absolute and SmartJoin returned it unjoined. The fix only treats these as special when they appear as an actual {{...}} template expression, restoring correct base-dir joining for ordinary paths. Includes filepathext_test.go cases for both the template and plain-substring forms. Minimal, no behavior change for real template usage. Ready for review — closes #3021.

This branch has not been deployed

No deployments
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.

SmartJoin incorrectly treats relative paths containing special variable names as special paths

1 participant