Skip Menu |

This queue is for tickets about the PathTools CPAN distribution.

Report information
The Basics
Id: 50378
Status: open
Priority: 0/
Queue: PathTools

People
Owner: Nobody in particular
Requestors: dagolden [...] cpan.org
jkeenan [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Stop undefined warnings from catpath
Calling catpath without a $file argument causes warnings about undefined $file. (Apparently some people use splitpath/catpath for a more complicated form of basename().) Patch below: Index: lib/File/Spec/Unix.pm =================================================================== --- lib/File/Spec/Unix.pm (revision 13385) +++ lib/File/Spec/Unix.pm (working copy) @@ -313,6 +313,7 @@ sub catpath { my ($self,$volume,$directory,$file) = @_; + my $file = '' unless defined $file; if ( $directory ne '' && $file ne '' &&
On Sat Oct 10 15:19:46 2009, DAGOLDEN wrote: Show quoted text
> Calling catpath without a $file argument causes warnings about undefined > $file. (Apparently some people use splitpath/catpath for a more > complicated form of basename().) > > Patch below: > > > Index: lib/File/Spec/Unix.pm > =================================================================== > --- lib/File/Spec/Unix.pm (revision 13385) > +++ lib/File/Spec/Unix.pm (working copy) > @@ -313,6 +313,7 @@ > > sub catpath { > my ($self,$volume,$directory,$file) = @_; > + my $file = '' unless defined $file; > > if ( $directory ne '' && > $file ne '' &&
1. Would we need to make this correction in other File::Spec::* files? 2. Would it be possible for you to submit a patch to dist/Cwd/t/Spec.t that (a) activates warnings, at least for a block; (b) demonstrates that the correction generates no warnings? Thank you very much. Jim Keenan
Subject: sub_catpath_definitions.txt
dist/Cwd/lib/File/Spec/Mac.pm:585:sub catpath { dist/Cwd/lib/File/Spec/Mac.pm-586- my ($self,$volume,$directory,$file) = @_; dist/Cwd/lib/File/Spec/Mac.pm-587- dist/Cwd/lib/File/Spec/Mac.pm-588- if ( (! $volume) && (! $directory) ) { dist/Cwd/lib/File/Spec/Mac.pm-589- $file =~ s/^:// if $file; dist/Cwd/lib/File/Spec/Mac.pm-590- return $file ; dist/Cwd/lib/File/Spec/Mac.pm-591- } dist/Cwd/lib/File/Spec/Mac.pm-592- dist/Cwd/lib/File/Spec/Mac.pm-593- # We look for a volume in $volume, then in $directory, but not both dist/Cwd/lib/File/Spec/Mac.pm-594- dist/Cwd/lib/File/Spec/Mac.pm-595- my ($dir_volume, $dir_dirs) = $self->splitpath($directory, 1); dist/Cwd/lib/File/Spec/Mac.pm-596- dist/Cwd/lib/File/Spec/Mac.pm-597- $volume = $dir_volume unless length $volume; dist/Cwd/lib/File/Spec/Mac.pm-598- my $path = $volume; # may be '' dist/Cwd/lib/File/Spec/Mac.pm-599- $path .= ':' unless (substr($path, -1) eq ':'); # ensure trailing ':' dist/Cwd/lib/File/Spec/Mac.pm-600- dist/Cwd/lib/File/Spec/Mac.pm-601- if ($directory) { dist/Cwd/lib/File/Spec/Mac.pm-602- $directory = $dir_dirs if $volume; dist/Cwd/lib/File/Spec/Mac.pm-603- $directory =~ s/^://; # remove leading ':' if any dist/Cwd/lib/File/Spec/Mac.pm-604- $path .= $directory; dist/Cwd/lib/File/Spec/Mac.pm-605- $path .= ':' unless (substr($path, -1) eq ':'); # ensure trailing ':' dist/Cwd/lib/File/Spec/Mac.pm-606- } dist/Cwd/lib/File/Spec/Mac.pm-607- dist/Cwd/lib/File/Spec/Mac.pm-608- if ($file) { dist/Cwd/lib/File/Spec/Mac.pm-609- $file =~ s/^://; # remove leading ':' if any dist/Cwd/lib/File/Spec/Mac.pm-610- $path .= $file; dist/Cwd/lib/File/Spec/Mac.pm-611- } dist/Cwd/lib/File/Spec/Mac.pm-612- dist/Cwd/lib/File/Spec/Mac.pm-613- return $path; dist/Cwd/lib/File/Spec/Mac.pm-614-} dist/Cwd/lib/File/Spec/Mac.pm-615- -- dist/Cwd/lib/File/Spec/OS2.pm:110:sub catpath { dist/Cwd/lib/File/Spec/OS2.pm-111- my ($self,$volume,$directory,$file) = @_; dist/Cwd/lib/File/Spec/OS2.pm-112- dist/Cwd/lib/File/Spec/OS2.pm-113- # If it's UNC, make sure the glue separator is there, reusing dist/Cwd/lib/File/Spec/OS2.pm-114- # whatever separator is first in the $volume dist/Cwd/lib/File/Spec/OS2.pm-115- $volume .= $1 dist/Cwd/lib/File/Spec/OS2.pm-116- if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s && dist/Cwd/lib/File/Spec/OS2.pm-117- $directory =~ m@^[^\\/]@s dist/Cwd/lib/File/Spec/OS2.pm-118- ) ; dist/Cwd/lib/File/Spec/OS2.pm-119- dist/Cwd/lib/File/Spec/OS2.pm-120- $volume .= $directory ; dist/Cwd/lib/File/Spec/OS2.pm-121- dist/Cwd/lib/File/Spec/OS2.pm-122- # If the volume is not just A:, make sure the glue separator is dist/Cwd/lib/File/Spec/OS2.pm-123- # there, reusing whatever separator is first in the $volume if possible. dist/Cwd/lib/File/Spec/OS2.pm-124- if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s && dist/Cwd/lib/File/Spec/OS2.pm-125- $volume =~ m@[^\\/]\Z(?!\n)@ && dist/Cwd/lib/File/Spec/OS2.pm-126- $file =~ m@[^\\/]@ dist/Cwd/lib/File/Spec/OS2.pm-127- ) { dist/Cwd/lib/File/Spec/OS2.pm-128- $volume =~ m@([\\/])@ ; dist/Cwd/lib/File/Spec/OS2.pm-129- my $sep = $1 ? $1 : '/' ; dist/Cwd/lib/File/Spec/OS2.pm-130- $volume .= $sep ; dist/Cwd/lib/File/Spec/OS2.pm-131- } dist/Cwd/lib/File/Spec/OS2.pm-132- dist/Cwd/lib/File/Spec/OS2.pm-133- $volume .= $file ; dist/Cwd/lib/File/Spec/OS2.pm-134- dist/Cwd/lib/File/Spec/OS2.pm-135- return $volume ; dist/Cwd/lib/File/Spec/OS2.pm-136-} dist/Cwd/lib/File/Spec/OS2.pm-137- dist/Cwd/lib/File/Spec/OS2.pm-138- dist/Cwd/lib/File/Spec/OS2.pm-139-sub abs2rel { dist/Cwd/lib/File/Spec/OS2.pm-140- my($self,$path,$base) = @_; -- dist/Cwd/lib/File/Spec/Unix.pm:352:sub catpath { dist/Cwd/lib/File/Spec/Unix.pm-353- my ($self,$volume,$directory,$file) = @_; dist/Cwd/lib/File/Spec/Unix.pm-354- dist/Cwd/lib/File/Spec/Unix.pm-355- if ( $directory ne '' && dist/Cwd/lib/File/Spec/Unix.pm-356- $file ne '' && dist/Cwd/lib/File/Spec/Unix.pm-357- substr( $directory, -1 ) ne '/' && dist/Cwd/lib/File/Spec/Unix.pm-358- substr( $file, 0, 1 ) ne '/' dist/Cwd/lib/File/Spec/Unix.pm-359- ) { dist/Cwd/lib/File/Spec/Unix.pm-360- $directory .= "/$file" ; dist/Cwd/lib/File/Spec/Unix.pm-361- } dist/Cwd/lib/File/Spec/Unix.pm-362- else { dist/Cwd/lib/File/Spec/Unix.pm-363- $directory .= $file ; dist/Cwd/lib/File/Spec/Unix.pm-364- } dist/Cwd/lib/File/Spec/Unix.pm-365- dist/Cwd/lib/File/Spec/Unix.pm-366- return $directory ; dist/Cwd/lib/File/Spec/Unix.pm-367-} dist/Cwd/lib/File/Spec/Unix.pm-368- dist/Cwd/lib/File/Spec/Unix.pm-369-=item abs2rel dist/Cwd/lib/File/Spec/Unix.pm-370- dist/Cwd/lib/File/Spec/Unix.pm-371-Takes a destination path and an optional base path returns a relative path dist/Cwd/lib/File/Spec/Unix.pm-372-from the base path to the destination path: dist/Cwd/lib/File/Spec/Unix.pm-373- dist/Cwd/lib/File/Spec/Unix.pm-374- $rel_path = File::Spec->abs2rel( $path ) ; dist/Cwd/lib/File/Spec/Unix.pm-375- $rel_path = File::Spec->abs2rel( $path, $base ) ; dist/Cwd/lib/File/Spec/Unix.pm-376- dist/Cwd/lib/File/Spec/Unix.pm-377-If $base is not present or '', then L<cwd()|Cwd> is used. If $base is dist/Cwd/lib/File/Spec/Unix.pm-378-relative, then it is converted to absolute form using dist/Cwd/lib/File/Spec/Unix.pm-379-L</rel2abs()>. This means that it is taken to be relative to dist/Cwd/lib/File/Spec/Unix.pm-380-L<cwd()|Cwd>. dist/Cwd/lib/File/Spec/Unix.pm-381- dist/Cwd/lib/File/Spec/Unix.pm-382-On systems that have a grammar that indicates filenames, this ignores the -- dist/Cwd/lib/File/Spec/VMS.pm:415:sub catpath { dist/Cwd/lib/File/Spec/VMS.pm-416- my($self,$dev,$dir,$file) = @_; dist/Cwd/lib/File/Spec/VMS.pm-417- dist/Cwd/lib/File/Spec/VMS.pm-418- # We look for a volume in $dev, then in $dir, but not both dist/Cwd/lib/File/Spec/VMS.pm-419- my ($dir_volume, $dir_dir, $dir_file) = $self->splitpath($dir); dist/Cwd/lib/File/Spec/VMS.pm-420- $dev = $dir_volume unless length $dev; dist/Cwd/lib/File/Spec/VMS.pm-421- $dir = length $dir_file ? $self->catfile($dir_dir, $dir_file) : $dir_dir; dist/Cwd/lib/File/Spec/VMS.pm-422- dist/Cwd/lib/File/Spec/VMS.pm-423- if ($dev =~ m|^(?<!\^)/+([^/]+)|) { $dev = "$1:"; } dist/Cwd/lib/File/Spec/VMS.pm-424- else { $dev .= ':' unless $dev eq '' or $dev =~ /:\Z(?!\n)/; } dist/Cwd/lib/File/Spec/VMS.pm-425- if (length($dev) or length($dir)) { dist/Cwd/lib/File/Spec/VMS.pm-426- $dir = "[$dir]" unless $dir =~ /(?<!\^)[\[<\/]/; dist/Cwd/lib/File/Spec/VMS.pm-427- $dir = vmspath($dir); dist/Cwd/lib/File/Spec/VMS.pm-428- } dist/Cwd/lib/File/Spec/VMS.pm-429- $dir = '' if length($dev) && ($dir eq '[]' || $dir eq '<>'); dist/Cwd/lib/File/Spec/VMS.pm-430- "$dev$dir$file"; dist/Cwd/lib/File/Spec/VMS.pm-431-} dist/Cwd/lib/File/Spec/VMS.pm-432- dist/Cwd/lib/File/Spec/VMS.pm-433-=item abs2rel (override) dist/Cwd/lib/File/Spec/VMS.pm-434- dist/Cwd/lib/File/Spec/VMS.pm-435-Attempt to convert an absolute file specification to a relative specification. dist/Cwd/lib/File/Spec/VMS.pm-436- dist/Cwd/lib/File/Spec/VMS.pm-437-=cut dist/Cwd/lib/File/Spec/VMS.pm-438- dist/Cwd/lib/File/Spec/VMS.pm-439-sub abs2rel { dist/Cwd/lib/File/Spec/VMS.pm-440- my $self = shift; dist/Cwd/lib/File/Spec/VMS.pm-441- return vmspath(File::Spec::Unix::abs2rel( $self, @_ )) dist/Cwd/lib/File/Spec/VMS.pm-442- if grep m{/}, @_; dist/Cwd/lib/File/Spec/VMS.pm-443- dist/Cwd/lib/File/Spec/VMS.pm-444- my($path,$base) = @_; dist/Cwd/lib/File/Spec/VMS.pm-445- $base = $self->_cwd() unless defined $base and length $base; -- dist/Cwd/lib/File/Spec/Win32.pm:286:sub catpath { dist/Cwd/lib/File/Spec/Win32.pm-287- my ($self,$volume,$directory,$file) = @_; dist/Cwd/lib/File/Spec/Win32.pm-288- dist/Cwd/lib/File/Spec/Win32.pm-289- # If it's UNC, make sure the glue separator is there, reusing dist/Cwd/lib/File/Spec/Win32.pm-290- # whatever separator is first in the $volume dist/Cwd/lib/File/Spec/Win32.pm-291- my $v; dist/Cwd/lib/File/Spec/Win32.pm-292- $volume .= $v dist/Cwd/lib/File/Spec/Win32.pm-293- if ( (($v) = $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s) && dist/Cwd/lib/File/Spec/Win32.pm-294- $directory =~ m@^[^\\/]@s dist/Cwd/lib/File/Spec/Win32.pm-295- ) ; dist/Cwd/lib/File/Spec/Win32.pm-296- dist/Cwd/lib/File/Spec/Win32.pm-297- $volume .= $directory ; dist/Cwd/lib/File/Spec/Win32.pm-298- dist/Cwd/lib/File/Spec/Win32.pm-299- # If the volume is not just A:, make sure the glue separator is dist/Cwd/lib/File/Spec/Win32.pm-300- # there, reusing whatever separator is first in the $volume if possible. dist/Cwd/lib/File/Spec/Win32.pm-301- if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s && dist/Cwd/lib/File/Spec/Win32.pm-302- $volume =~ m@[^\\/]\Z(?!\n)@ && dist/Cwd/lib/File/Spec/Win32.pm-303- $file =~ m@[^\\/]@ dist/Cwd/lib/File/Spec/Win32.pm-304- ) { dist/Cwd/lib/File/Spec/Win32.pm-305- $volume =~ m@([\\/])@ ; dist/Cwd/lib/File/Spec/Win32.pm-306- my $sep = $1 ? $1 : '\\' ; dist/Cwd/lib/File/Spec/Win32.pm-307- $volume .= $sep ; dist/Cwd/lib/File/Spec/Win32.pm-308- } dist/Cwd/lib/File/Spec/Win32.pm-309- dist/Cwd/lib/File/Spec/Win32.pm-310- $volume .= $file ; dist/Cwd/lib/File/Spec/Win32.pm-311- dist/Cwd/lib/File/Spec/Win32.pm-312- return $volume ; dist/Cwd/lib/File/Spec/Win32.pm-313-} dist/Cwd/lib/File/Spec/Win32.pm-314- dist/Cwd/lib/File/Spec/Win32.pm-315-sub _same { dist/Cwd/lib/File/Spec/Win32.pm-316- lc($_[1]) eq lc($_[2]);
Subject: Re: [rt.cpan.org #50378] [PATCH] Stop undefined warnings from catpath
Date: Sat, 23 Nov 2013 22:50:14 -0500
To: bug-PathTools [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
On Sat, Nov 23, 2013 at 8:49 PM, James E Keenan via RT <bug-PathTools@rt.cpan.org> wrote: Show quoted text
> 1. Would we need to make this correction in other File::Spec::* files?
Or something like it, probably. Most of the arguments get tested or concatenated without any check that they are defined. Show quoted text
> 2. Would it be possible for you to submit a patch to dist/Cwd/t/Spec.t that (a) activates warnings, at least for a block; (b) demonstrates that the correction generates no warnings?
Unfortunately, I'm too short on tuits to do so, but this is a straightforward "pure perl" fix for someone motivated to attempt it. David -- David Golden <dagolden@cpan.org> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg