| Posted on 2009-06-15 14:50:02-07 by tdrillich |
| File::Spec::Unix buggy no_upwards |
|
Hi,
the no_upwards method doesn't remove updirs correctly, it just strips '.' and '..' entries, but it has to remove
the upper directory too on .. entries.
a diff to PathTools-3.30 follows which correct that behaviour:
diff -Nur PathTools-3.30/Changes PathTools-3.31/Changes
--- PathTools-3.30/Changes 2009-05-10 10:58:10.000000000 +0200
+++ PathTools-3.31/Changes 2009-06-15 16:40:24.000000000 +0200
@@ -1,5 +1,10 @@
Revision history for Perl distribution PathTools.
+3.31 - Mon Jun 15 16:39:00 2009
+
+- fix no_upwards
+ Thomas Drillich <th@drillich.com>
+
3.30 - Sun May 10 10:55:00 2009
- Promote to stable release.
diff -Nur PathTools-3.30/lib/File/Spec/Unix.pm PathTools-3.31/lib/File/Spec/Unix.pm
--- PathTools-3.30/lib/File/Spec/Unix.pm 2009-05-10 10:58:10.000000000 +0200
+++ PathTools-3.31/lib/File/Spec/Unix.pm 2009-06-15 16:29:07.000000000 +0200
@@ -184,7 +184,17 @@
sub no_upwards {
my $self = shift;
- return grep(!/^\.{1,2}\z/s, @_);
+ my @f=$self->splitdir($self->join(@_));
+ my $curr=$self->curdir();
+ my $up=$self->updir();
+ for(my $i=0; $i <= $#f; $i++) {
+ if($f[$i] eq $curr) {
+ splice(@f, $i, 1);
+ } elsif($f[$i] eq $up && $i) {
+ splice(@f, $i-1, 2);
+ }
+ }
+ return wantarray ? @f : $self->join(@f);
}
=item case_tolerant
diff -Nur PathTools-3.30/t/Spec.t PathTools-3.31/t/Spec.t
--- PathTools-3.30/t/Spec.t 2009-05-10 10:58:10.000000000 +0200
+++ PathTools-3.31/t/Spec.t 2009-06-15 16:36:33.000000000 +0200
@@ -143,6 +143,11 @@
[ "Unix->rel2abs('../t4','/t1/t2/t3')", '/t1/t2/t3/../t4' ],
[ "Unix->rel2abs('/t1','/t1/t2/t3')", '/t1' ],
+[ "Unix->no_upwards('./a/./x/../b/.')", 'a,b'],
+[ "Unix->no_upwards('../a/./x/../b/.')", '..,a,b'],
+[ "Unix->no_upwards('/a/./x/../b/.')", ',a,b'],
+[ "Unix->no_upwards('a/./x/../b/.')", 'a,b'],
+
[ "Win32->case_tolerant()", '1' ],
[ "Win32->rootdir()", '\\' ],
|
| Direct Responses: Write a response |