Skip to content

Fix ExpandPath so it always returns a clean path and resolves "~" to the home directory - #658

Open
anuragkumar19 wants to merge 1 commit into
alecthomas:masterfrom
anuragkumar19:expand-path-patch
Open

anuragkumar19 wants to merge 1 commit into
alecthomas:masterfrom
anuragkumar19:expand-path-patch

Conversation

@anuragkumar19

Copy link
Copy Markdown

Issues

  1. Currently, ExpandPath does a filepath.IsAbs check at the start, and if the path is absolute, it returns the path unmodified. This skips the cleaning normally performed by filepath.Join or filepath.Abs on other code paths. For example, the path /a/c/../c is returned unmodified.
  2. The path ~ doesn't resolve to the home directory; instead, it gets joined with the working dir by filepath.Abs.

Fixes

  1. Remove the filepath.IsAbs check. If the path is already absolute, filepath.Abs will clean and return it.
  2. Add handling to resolve ~ to the home directory.
  3. Add tests for ExpandPath.

Tests

  • go test ./... passes.

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.

1 participant