-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File::Spec - catfile wrongly makes relative path absolute #8760
Comments
From [email protected]Created by [email protected]Consider: If the first element in the list passed to File::Spec->catfile The behaviour is similar on other architectures as well, in that On Windows, "\blib" is returned. Solaris returns "/ blib" (with IMHO, leading and trailing empty (or undef) elements should be File::Spec->catdir has the same bug. Solution (e.g. for File::Spec::Unix.pm): ---snip--- Inline Patch--- Unix.pm 2006-10-11 19:11:03.000000000 +0200
+++ Unix.pm.new 2007-02-01 21:51:22.000000000 +0100
@@ -78,6 +78,7 @@
sub catdir {
my $self = shift;
+ shift @_ while @_ && $_[0] =~ /^$/;
$self->canonpath(join('/', @_, '')); # '' because need a trailing '/'
}
@@ -91,6 +92,7 @@
sub catfile {
my $self = shift;
+ shift @_ while @_ && $_[0] =~ /^$/;
my $file = $self->canonpath(pop @_);
return $file unless @_;
my $dir = $self->catdir(@_);
---snip---
--shmem Perl Info
|
From @schwernGeorg Moritz (via RT) wrote:
I do not believe this is a bug but an underdocumented feature of cat*. The intention is to mirror the behavior of splitdir() which uses an empty string to indicate the root directory. This allows splitdir and catdir/file to round trip. Additionally, "" really is the true name of the root directory. Consider it this way and it will make more sense. catdir() takes a list of directory names. "/" is a path separator and not part of the directory name. With that in mind, how do you represent the root directory? What is its name? We call it / but really its name is the empty string. The directory-which-shall-not-be-named. The directory formerly known as "/". This is not just a File::Spec thing but an accurate way of looking at the structure of the Unix filesystem. Consider it another way. Given that the point of File::Spec is to be filesystem agnostic, how would you put together an absolute path? You can't refer to it as "/", that's Unix specific. That it accepts undef this is simply because undef becomes an empty string when used as a string. Turn on warnings. |
The RT System itself - Status changed from 'new' to 'open' |
From [email protected]Created by [email protected]Consider: If the first element in the list passed to File::Spec->catfile The behaviour is similar on other architectures as well, in that On Windows, "\blib" is returned. Solaris returns "/ blib" (with IMHO, leading and trailing empty (or undef) elements should be File::Spec->catdir has the same bug. Solution (e.g. for File::Spec::Unix.pm): ---snip--- Inline Patch--- Unix.pm 2006-10-11 19:11:03.000000000 +0200
+++ Unix.pm.new 2007-02-01 21:51:22.000000000 +0100
@@ -78,6 +78,7 @@
sub catdir {
my $self = shift;
+ shift @_ while @_ && $_[0] =~ /^$/;
$self->canonpath(join('/', @_, '')); # '' because need a trailing '/'
}
@@ -91,6 +92,7 @@
sub catfile {
my $self = shift;
+ shift @_ while @_ && $_[0] =~ /^$/;
my $file = $self->canonpath(pop @_);
return $file unless @_;
my $dir = $self->catdir(@_);
---snip---
--shmem Perl Info
|
@rgs - Status changed from 'open' to 'rejected' |
From @adamkennedyCan I strongly recommend that before you make any changes here you add Because as I understand it, "" intentionally represents the root path. DB<4> x File::Spec->splitdir('/foo/bar') DB<5> x File::Spec->catdir(File::Spec->splitdir('/foo/bar')) I seem to recall I rely on this "null string is root" in a number of As for the undef case, I'm ambivalent, but I'd rather see an error than Adam K Georg Moritz wrote:
|
Migrated from rt.perl.org#41422 (status was 'rejected')
Searchable as RT41422$
The text was updated successfully, but these errors were encountered: