Skip to content

fix(File::Spec): abs2rel returns "." when path equals base#588

Merged
fglock merged 1 commit intomasterfrom
fix/filespec-abs2rel-curdir
Apr 28, 2026
Merged

fix(File::Spec): abs2rel returns "." when path equals base#588
fglock merged 1 commit intomasterfrom
fix/filespec-abs2rel-curdir

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 28, 2026

Summary

Fixes File::Spec->abs2rel($p, $p) returning an empty string instead of ".", which broke Path::Iterator::Rule with relative => 1.

Root cause

Java's Path.relativize() returns an empty Path when both paths are equal, while Perl's File::Spec->abs2rel returns the curdir token ".". Path::Iterator::Rule (when called with relative => 1) uses abs2rel($origin, $origin) for the root entry, then feeds the result into Path::Tiny->path(...), which dies on the empty string:

Path::Tiny paths require defined, positive-length parts at t/relative.t line 54.

Fix

In FileSpec.abs2rel, map an empty relativize() result to "." to match Perl's behavior.

Test plan

  • make (full unit test suite passes)
  • jperl -MFile::Spec -e 'print File::Spec->abs2rel("/tmp/foo", "/tmp/foo")' now prints . (was empty)
  • jcpan -t Path::Iterator::Rule — all 23 test files / 91 subtests pass (previously t/relative.t failed with exit 255)

Generated with Devin

Java's Path.relativize() returns an empty Path when the two paths are
equal, but Perl's File::Spec->abs2rel returns the curdir token ".".
This mismatch broke Path::Iterator::Rule's relative iteration: with
relative => 1 the iterator calls abs2rel($origin, $origin) for the
root entry, then feeds the result into Path::Tiny->path(...), which
errors out with "Path::Tiny paths require defined, positive-length
parts" on the empty string.

Map an empty relativize() result to "." in FileSpec.abs2rel so it
matches Perl's behavior. With the fix, `jcpan -t Path::Iterator::Rule`
now passes all 23 test files (91 subtests).

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit bb20cc0 into master Apr 28, 2026
2 checks passed
@fglock fglock deleted the fix/filespec-abs2rel-curdir branch April 28, 2026 13:03
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