This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: bug in File::Spec 0.82 (canonpath)
authorBarrie Slaymaker <barries@slaysys.com>
Tue, 14 Aug 2001 14:32:25 +0000 (10:32 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 15 Aug 2001 03:28:20 +0000 (03:28 +0000)
Message-ID: <20010814143225.A19822@jester.slaysys.com>

p4raw-id: //depot/perl@11675

lib/File/Spec.t
lib/File/Spec/Unix.pm

index c6d155f..b6adc77 100755 (executable)
@@ -53,7 +53,10 @@ BEGIN {
 
 [ "Unix->canonpath('')",                                      ''          ],
 [ "Unix->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
-[ "Unix->canonpath('/.')",                                    '/.'        ],
+[ "Unix->canonpath('/.')",                                    '/'         ],
+[ "Unix->canonpath('/./')",                                   '/'         ],
+[ "Unix->canonpath('/a/./')",                                 '/a'        ],
+[ "Unix->canonpath('/a/.')",                                  '/a'        ],
 
 [  "Unix->abs2rel('/t1/t2/t3','/t1/t2/t3')",          ''                   ],
 [  "Unix->abs2rel('/t1/t2/t4','/t1/t2/t3')",          '../t4'              ],
@@ -63,7 +66,7 @@ BEGIN {
 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
 [  "Unix->abs2rel('/','/t1/t2/t3')",                  '../../..'           ],
 [  "Unix->abs2rel('///','/t1/t2/t3')",                '../../..'           ],
-[  "Unix->abs2rel('/.','/t1/t2/t3')",                 '../../../.'         ],
+[  "Unix->abs2rel('/.','/t1/t2/t3')",                 '../../..'           ],
 [  "Unix->abs2rel('/./','/t1/t2/t3')",                '../../..'           ],
 #[ "Unix->abs2rel('../t4','/t1/t2/t3')",              '../t4'              ],
 
index 00899e7..ae2a949 100644 (file)
@@ -26,7 +26,7 @@ Methods for manipulating file specifications.
 =item canonpath
 
 No physical check on the filesystem, but a logical cleanup of a
-path. On UNIX eliminated successive slashes and successive "/.".
+path. On UNIX eliminate successive slashes and successive "/.".
 
     $cpath = File::Spec->canonpath( $path ) ;
 
@@ -41,7 +41,7 @@ sub canonpath {
       $node = $1;
     }
     $path =~ s|/+|/|g unless($^O eq 'cygwin');     # xx////xx  -> xx/xx
-    $path =~ s|(/\.)+/|/|g;                        # xx/././xx -> xx/xx
+    $path =~ s@(/\.)+(/|\Z(?!\n))@/@g;             # xx/././xx -> xx/xx
     $path =~ s|^(\./)+||s unless $path eq "./";    # ./xx      -> xx
     $path =~ s|^/(\.\./)+|/|s;                     # /../../xx -> xx
     $path =~ s|/\Z(?!\n)|| unless $path eq "/";          # xx/       -> xx