This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File::Spec->catfile not canonicalizing consistently
authorMichael G. Schwern <schwern@pobox.com>
Fri, 30 Aug 2002 03:40:45 +0000 (20:40 -0700)
committerhv <hv@crypt.org>
Wed, 4 Sep 2002 11:31:42 +0000 (11:31 +0000)
Message-ID: <20020830104044.GF859@ool-18b93024.dyn.optonline.net>

p4raw-id: //depot/perl@17828

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

index 87ee505..d9615c0 100644 (file)
@@ -88,7 +88,7 @@ complete path ending with a filename
 
 sub catfile {
     my $self = shift;
-    my $file = pop @_;
+    my $file = File::Spec->canonpath(pop @_);
     return $file unless @_;
     my $dir = $self->catdir(@_);
     $dir .= "/" unless substr($dir,-1) eq "/";
index 186052b..791b004 100644 (file)
@@ -95,7 +95,7 @@ complete path ending with a filename
 
 sub catfile {
     my $self = shift;
-    my $file = pop @_;
+    my $file = $self->canonpath(pop @_);
     return $file unless @_;
     my $dir = $self->catdir(@_);
     $dir .= "\\" unless substr($dir,-1) eq "\\";
index 3f18a35..35b2e6f 100644 (file)
@@ -50,7 +50,11 @@ if ($^O eq 'MacOS') {
 @tests = (
 # [ Function          ,            Expected          ,         Platform ]
 
-[ "Unix->catfile('a','b','c')", 'a/b/c'  ],
+[ "Unix->catfile('a','b','c')",         'a/b/c'  ],
+[ "Unix->catfile('a','b','./c')",       'a/b/c'  ],
+[ "Unix->catfile('./a','b','c')",       'a/b/c'  ],
+[ "Unix->catfile('c')",                 'c' ],
+[ "Unix->catfile('./c')",               'c' ],
 
 [ "Unix->splitpath('file')",            ',,file'            ],
 [ "Unix->splitpath('/d1/d2/d3/')",      ',/d1/d2/d3/,'      ],
@@ -87,8 +91,6 @@ if ($^O eq 'MacOS') {
 [ "Unix->catdir('','d1','d2','d3')",    '/d1/d2/d3' ],
 [ "Unix->catdir('d1','d2','d3')",       'd1/d2/d3'  ],
 
-[ "Unix->catfile('a','b','c')", 'a/b/c' ],
-
 [ "Unix->canonpath('')",                                      ''          ],
 [ "Unix->canonpath('///../../..//./././a//b/.././c/././')",   '/a/b/../c' ],
 [ "Unix->canonpath('/.')",                                    '/'         ],
@@ -184,7 +186,12 @@ if ($^O eq 'MacOS') {
 [ "Win32->catdir('A:/d1','B:/d2','d3','')", 'A:\\d1\\B:\\d2\\d3' ],
 [ "Win32->catdir('A:/')",                   'A:\\'               ],
 
-[ "Win32->catfile('a','b','c')", 'a\\b\\c' ],
+[ "Win32->catfile('a','b','c')",        'a\\b\\c' ],
+[ "Win32->catfile('a','b','.\\c')",      'a\\b\\c'  ],
+[ "Win32->catfile('.\\a','b','c')",      'a\\b\\c'  ],
+[ "Win32->catfile('c')",                'c' ],
+[ "Win32->catfile('.\\c')",              'c' ],
+
 
 [ "Win32->canonpath('')",               ''                    ],
 [ "Win32->canonpath('a:')",             'A:'                  ],
@@ -226,6 +233,13 @@ if ($^O eq 'MacOS') {
 [ "Win32->rel2abs('temp','//prague_main/work')",        '\\\\prague_main\\work\\temp'     ],
 [ "Win32->rel2abs('../','//prague_main/work')",         '\\\\prague_main\\work\\..'       ],
 
+
+[ "VMS->catfile('a','b','c')",         '[.a.b]c'  ],
+[ "VMS->catfile('a','b','[]c')",       '[.a.b]c'  ],
+[ "VMS->catfile('[.a]','b','c')",       '[.a.b]c'  ],
+[ "VMS->catfile('c')",                 'c' ],
+[ "VMS->catfile('[]c')",               'c' ],
+
 [ "VMS->splitpath('file')",                                       ',,file'                                   ],
 [ "VMS->splitpath('[d1.d2.d3]')",                                 ',[d1.d2.d3],'                               ],
 [ "VMS->splitpath('[.d1.d2.d3]')",                                ',[.d1.d2.d3],'                              ],
@@ -294,7 +308,12 @@ if ($^O eq 'MacOS') {
 [ "VMS->rel2abs('[t1]','[t1.t2.t3]')",           '[t1]'             ],
 
 [ "OS2->catdir('A:/d1','B:/d2','d3','')", 'A:/d1/B:/d2/d3' ],
+
 [ "OS2->catfile('a','b','c')",            'a/b/c'          ],
+[ "OS2->catfile('a','b','./c')",          'a/b/c'  ],
+[ "OS2->catfile('./a','b','c')",          'a/b/c'  ],
+[ "OS2->catfile('c')",                    'c' ],
+[ "OS2->catfile('./c')",                  'c' ],
 
 
 [ "Mac->catpath('','','')",              ''                ],