Skip to content

Comments

fix: resolve . and .. components in middle of file paths (#108)#215

Open
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-path-canonicalization
Open

fix: resolve . and .. components in middle of file paths (#108)#215
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-path-canonicalization

Conversation

@Koan-Bot
Copy link
Contributor

Summary

  • Rewrites _abs_path_to_file from regex-based loop to component-based path resolution
  • Fixes paths like /there/./xyz (was not resolved — caused strict mode violations per Convert relative paths on opendir/open #108)
  • Fixes /there/.. producing empty string instead of /
  • Fixes /../foo not being handled (only /.. had a special case)
  • Fixes / being stripped to empty string by the trailing slash regex

What changed

The old approach used iterative regex substitutions that only handled /. at end of path and had edge cases where .. resolution could produce empty strings. The new approach splits the path into components, filters . and resolves .., then rejoins — handling all positions naturally.

Test plan

  • 12 new unit tests for _abs_path_to_file edge cases (. mid-path, .. at root, multiple slashes, root preservation)
  • 5 new functional tests verifying stat/-d/-e/-f on mocked files accessed through /./ and /../ paths
  • All existing tests preserved and passing

🤖 Generated with Claude Code

Replace regex-based path normalization loop with component-based
resolution. The old approach only handled /. at end of path and
could produce empty strings for paths like /there/.. — the new
split/resolve approach handles all positions correctly:

- /there/./xyz now resolves to /there/xyz (was unchanged before)
- /there/.. resolves to / (was empty string before)
- /../foo resolves to /foo (was unhandled)
- / preserves as / (was stripped to empty by trailing slash regex)

Also moves tilde expansion before absolutification for clarity and
removes the special-case return for /.. (now handled naturally).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-path-canonicalization branch from 8b9079a to 6bb28ab Compare February 24, 2026 21:33
@atoomic atoomic marked this pull request as ready for review February 25, 2026 05:31
@atoomic atoomic requested a review from toddr February 25, 2026 05:33
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.

2 participants