fix(File::Spec): abs2rel returns "." when path equals base#588
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
File::Spec->abs2rel($p, $p)returning an empty string instead of".", which brokePath::Iterator::Rulewithrelative => 1.Root cause
Java's
Path.relativize()returns an emptyPathwhen both paths are equal, while Perl'sFile::Spec->abs2relreturns the curdir token".".Path::Iterator::Rule(when called withrelative => 1) usesabs2rel($origin, $origin)for the root entry, then feeds the result intoPath::Tiny->path(...), which dies on the empty string:Fix
In
FileSpec.abs2rel, map an emptyrelativize()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 (previouslyt/relative.tfailed with exit 255)Generated with Devin