Subject: | Double Backslash in C:\\Foo\Bar |
Hello again. I will write the patch for that other thing, but in the meantime here's something that I reckon is an actual bug rather than a mere wishlist item. I encountered it on Windows, but here's an example using foreign_dir:
% perl -MPath::Class=foreign_dir -wde0
main::(-e:1): 0
DB<1> $d = foreign_dir 'Win32', 'C:\\'
DB<2> p $d
C:\
DB<3> p $d->subdir('Foo/Bar')
C:\\Foo\Bar
There shouldn't be 2 backslashes just after the volume. The problem is that after Path::Class::Dir->new breaks C: off from C:\ for the volume, it leaves $dirs containing just a single path separator; invoking splitdir on $dirs creates two empty array items (one for the non-existent path either side of the separator), which turn into 2 backslashes when the array is concatenated for output.
The attached patch contains some tests which fail with version 0.08 and a fix to make them pass.
Cheers.
Smylers
diff -ur -r /root/.cpan/build/Path-Class-0.08/Changes ./Changes
--- /root/.cpan/build/Path-Class-0.08/Changes Tue Dec 28 14:31:32 2004
+++ ./Changes Tue Apr 5 15:26:23 2005
@@ -1,5 +1,10 @@
Revision history for Perl extension Path::Class.
+0.09 not yet released
+
+ - Fixed a bug that could result in double backslashes between the volume and
+ path (such as C:\\Foo\Bar). [Smylers]
+
0.08 Tue Dec 28 08:26:56 CST 2004
- Fixed a typo in the module name in the docs. [Chris Dolan]
diff -ur -r /root/.cpan/build/Path-Class-0.08/lib/Path/Class/Dir.pm ./lib/Path/Class/Dir.pm
--- /root/.cpan/build/Path-Class-0.08/lib/Path/Class/Dir.pm Tue Dec 28 14:31:32 2004
+++ ./lib/Path/Class/Dir.pm Tue Apr 5 15:23:49 2005
@@ -18,7 +18,7 @@
);
($self->{volume}, my $dirs) = $s->splitpath( $s->canonpath($first) , 1);
- $self->{dirs} = [map $s->splitdir($_), $dirs, @_];
+ $self->{dirs} = [$s->splitdir($s->catdir($dirs, @_))];
return $self;
}
diff -ur -r /root/.cpan/build/Path-Class-0.08/t/02-foreign.t ./t/02-foreign.t
--- /root/.cpan/build/Path-Class-0.08/t/02-foreign.t Tue Dec 28 14:31:32 2004
+++ ./t/02-foreign.t Tue Apr 5 15:22:58 2005
@@ -1,6 +1,6 @@
use Test;
use strict;
-BEGIN { plan tests => 20 };
+BEGIN { plan tests => 24 };
use Path::Class qw(file dir foreign_file foreign_dir);
ok(1);
@@ -29,6 +29,13 @@
ok $dir->as_foreign('Win32'), 'dir\subdir';
ok $dir->as_foreign('Mac'), ':dir:subdir:';
ok $dir->as_foreign('OS2'), 'dir/subdir';
+
+$dir = foreign_dir('Win32', 'C:\\');
+ok $dir, 'C:\\';
+$dir = foreign_dir('Win32', 'C:/');
+ok $dir, 'C:\\';
+ok $dir->subdir('Program Files'), 'C:\\Program Files';
+ok +(dir $dir, 'Program Files'), 'C:\\Program Files';
if ($^O eq 'VMS') {
ok $dir->as_foreign('VMS'), '[.dir.subdir]';