Skip to content

Comments

fix: preserve root path '/' in _abs_path_to_file normalization#213

Closed
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-abs-path-root
Closed

fix: preserve root path '/' in _abs_path_to_file normalization#213
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-abs-path-root

Conversation

@Koan-Bot
Copy link
Contributor

Summary

  • Fix trailing slash stripping in _abs_path_to_file that incorrectly converted bare / to empty string
  • Paths like /foo/.. (resolving to /) and bare / itself were falling through to the CWD-based relative path handler instead of returning /
  • One-character fix: use lookbehind (?<=.) to prevent stripping / when it's the only character

Context

Found while investigating #108. The . case (/there/.) already resolved correctly, but the .. case (/there/../) was broken because the normalization loop would reduce the path to /, then strip that final slash to an empty string.

Test plan

  • Added 3 new _abs_path_to_file unit tests: bare /, /there/.., /a/b/../../c
  • Added integration tests verifying -d and _mock_stat resolve /parent/. and /parent/child/.. correctly

🤖 Generated with Claude Code

The trailing slash stripping regex s{/$}{} incorrectly converted bare
'/' to an empty string, causing paths like '/foo/..' (which resolve to
'/') and bare '/' itself to fall through to the CWD-based relative path
handler instead of returning '/'.

Fix: use a lookbehind (?<=.) to require at least one character before
the trailing slash, so '/' alone is never stripped.

Added tests for '/', '/there/..', '/a/b/../../c', and integration
tests verifying _mock_stat resolves /. and /.. paths correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Koan-Bot
Copy link
Contributor Author

Note: PR #215 supersedes this fix. The broader component-based rewrite of _abs_path_to_file in #215 naturally handles root path preservation along with several other edge cases (resolving /. in middle of paths, /.. at root, etc.).

@Koan-Bot
Copy link
Contributor Author

Superseded by #215 which provides a comprehensive component-based path canonicalization fix.

@Koan-Bot Koan-Bot closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant