Skip to content

feat(utils): enhance ExpandTilde to support ~username#295

Merged
pashkov256 merged 2 commits intopashkov256:mainfrom
AliyaRazyapova:feature/expand-tilde-user
Feb 26, 2026
Merged

feat(utils): enhance ExpandTilde to support ~username#295
pashkov256 merged 2 commits intopashkov256:mainfrom
AliyaRazyapova:feature/expand-tilde-user

Conversation

@AliyaRazyapova
Copy link
Copy Markdown
Contributor

Description

This PR enhances the ExpandTilde function in the utils package to support expanding ~username paths (e.g., ~john/documents). Previously, only ~ (current user) was expanded correctly; ~username was ignored.

Changes

  • Added support for ~username using os/user.Lookup().
  • Fixed path splitting to handle both Unix (/) and Windows (\) separators.
  • Improved error handling – if user lookup fails, the original path is returned (backward compatible).
  • Added comprehensive unit tests covering:
    • ~ and ~/subpath
    • ~username/subpath (for existing user)
    • non-existing user (fallback to original path)
    • edge cases (empty string, tilde not at start)

Testing

  • All tests pass
  • Manual verification with various inputs.

Closes #115

@pashkov256
Copy link
Copy Markdown
Owner

Hi @AliyaRazyapova! The job failed because two files are not properly gofmt formatted:

internal/utils/utils.go
internal/utils/utils_test.go
Solution: Run gofmt on both files to automatically format them. In your project root, run:

gofmt -w internal/utils/utils.go internal/utils/utils_test.go

Run and commit the formatted files, and push your changes. This will resolve the lint (gofmt) errors and allow the CI job to pass.

@pashkov256 pashkov256 merged commit 77f1574 into pashkov256:main Feb 26, 2026
1 check passed
@pashkov256
Copy link
Copy Markdown
Owner

Hi @AliyaRazyapova . Great solution, thanks for contributing to the repository!!
Maybe you would be interested in the Russian-speaking community of Open Source developers, we share our projects, find where to contribute and support each other:
https://t.me/OpenSource_Chat

We also have a platform where you can find issues and contribution projects:
https://opensourcehub.tech/

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.

Add support for "~" in path on linux

2 participants