Skip to content

Only abbreviate paths inside the home directory - #89

Open
hakarrr wants to merge 2 commits into
xolox:masterfrom
hakarrr:fix-format-path-home-boundary
Open

hakarrr wants to merge 2 commits into
xolox:masterfrom
hakarrr:fix-format-path-home-boundary

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 24, 2026

Copy link
Copy Markdown

Problem

format_path() uses a string prefix to decide whether a path is inside HOME. With HOME=/home/user, /home/username/file is rendered as ~/../username/file, even though it is not inside the home directory. The documented abbreviation is intended for the home directory and its descendants.

Change

Require either an exact home-directory match or a prefix ending at a path separator. Preserve normalization, trailing separators, exact-home rendering and filesystem-root homes. The implementation keeps the project's older Python compatibility rather than using os.path.commonpath.

Tests

  • Three new test methods cover sibling prefixes, descendants, exact home, parent paths, normalization, trailing separators, filesystem-root homes and an empty HOME.
  • The boundary test fails on the unchanged base; root/empty-home tests are controls.
  • Full suite: 72 passed on CPython 3.9.25, 3.10.12, 3.11.17 and 3.12.15. The unchanged base has 69 tests.
  • Full combined line/branch coverage is 91%; the modified path-formatting branches are covered.
  • Changed-file flake8 including docstring checks, git diff --check, wheel and sdist passed.

Python 2, older Python versions, Windows and macOS were not tested locally. Hosted CI has not been verified green. No test or CI configuration changed.

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