From cd66b2739b8a8db5e5ca8ff7f278fc074d5b5bf2 Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Tue, 28 Apr 2026 14:48:54 +0200 Subject: [PATCH] fix(File::Spec): abs2rel returns "." when path equals base 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> --- src/main/java/org/perlonjava/core/Configuration.java | 4 ++-- .../java/org/perlonjava/runtime/perlmodule/FileSpec.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/perlonjava/core/Configuration.java b/src/main/java/org/perlonjava/core/Configuration.java index 260a4dcf0..f3ec8ca8a 100644 --- a/src/main/java/org/perlonjava/core/Configuration.java +++ b/src/main/java/org/perlonjava/core/Configuration.java @@ -33,7 +33,7 @@ public final class Configuration { * Automatically populated by Gradle/Maven during build. * DO NOT EDIT MANUALLY - this value is replaced at build time. */ - public static final String gitCommitId = "435af2ae7"; + public static final String gitCommitId = "f7bbbc40b"; /** * Git commit date of the build (ISO format: YYYY-MM-DD). @@ -48,7 +48,7 @@ public final class Configuration { * Parsed by App::perlbrew and other tools via: perl -V | grep "Compiled at" * DO NOT EDIT MANUALLY - this value is replaced at build time. */ - public static final String buildTimestamp = "Apr 28 2026 14:34:02"; + public static final String buildTimestamp = "Apr 28 2026 14:48:58"; // Prevent instantiation private Configuration() { diff --git a/src/main/java/org/perlonjava/runtime/perlmodule/FileSpec.java b/src/main/java/org/perlonjava/runtime/perlmodule/FileSpec.java index 82863be92..58e380112 100644 --- a/src/main/java/org/perlonjava/runtime/perlmodule/FileSpec.java +++ b/src/main/java/org/perlonjava/runtime/perlmodule/FileSpec.java @@ -528,6 +528,11 @@ public static RuntimeList abs2rel(RuntimeArray args, int ctx) { } String relPath = baseObj.relativize(pathObj).toString(); + // Perl's File::Spec->abs2rel returns "." (curdir) when path equals base, + // but Java's Path.relativize returns an empty string in that case. + if (relPath.isEmpty()) { + relPath = "."; + } return new RuntimeScalar(relPath).getList(); }