Repository navigation
fix: only treat special dirs as absolute when used as template expressions (Closes #3021) - #3105
Open
pethapixels-create wants to merge 2 commits into
Open
pethapixels-create wants to merge 2 commits into
pethapixels-create wants to merge 2 commits into
Conversation
…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.
Author
|
CI/triage note: Branch is |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes
SmartJoin/IsAbsso 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
isSpecialDirmatched 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, causingSmartJointo 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.gocoveringIsAbsandSmartJoin, including regression cases for relative paths containing.ROOT_DIR,.TASKFILE_DIR, and.USER_WORKING_DIR.Closes #3021