Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 560 forks source link

File::Spec and leading/trailing space #8011

Closed p5pRT closed 19 years ago

p5pRT commented 19 years ago

Migrated from rt.perl.org#36510 (status was 'resolved')

Searchable as RT36510$

p5pRT commented 19 years ago

From @schwern

rt.perl.org 24691 is about CPAN.pm saying that a path with a leading space is not absolute. The issue is File​::Spec... maybe. file_name_is_absolute() i does not recognize " /foo" as being absolute.

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute(" /foo")'

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute("/foo")' 1

canonpath() does not clean up leading or trailing space.

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath("/foo")' /foo

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath(" /foo")' /foo $ perl -wle 'use File​::Spec; print q["].File​::Spec->canonpath(" /foo ").q["]' " /foo "

Should it? Does leading and trailing space have any meaning in a Unix path?

-- Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern Don't try the paranormal until you know what's normal.   -- "Lords and Ladies" by Terry Prachett

p5pRT commented 19 years ago

From @pjcj

On Mon\, Jul 11\, 2005 at 11​:41​:04PM -0700\, Michael G Schwern wrote​:

rt.perl.org 24691 is about CPAN.pm saying that a path with a leading space is not absolute. The issue is File​::Spec... maybe. file_name_is_absolute() i does not recognize " /foo" as being absolute.

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute(" /foo")'

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute("/foo")' 1

canonpath() does not clean up leading or trailing space.

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath("/foo")' /foo

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath(" /foo")' /foo $ perl -wle 'use File​::Spec; print q["].File​::Spec->canonpath(" /foo ").q["]' " /foo "

Should it? Does leading and trailing space have any meaning in a Unix path?

Certainly.

$ mkdir ' ' $ touch ' /foo ' $ ls -lRQ "."​: total 4 drwxrwxr-x 2 pjcj pjcj 4096 2005-07-12 11​:01 " "

"./ "​: total 0 -rw-rw-r-- 1 pjcj pjcj 0 2005-07-12 11​:01 "foo "

So it seems to me that File​:Spec is doing the right thing here.

-- Paul Johnson - paul@​pjcj.net http​://www.pjcj.net

p5pRT commented 19 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 19 years ago

From @hvds

Michael G Schwern (via RT) \perlbug\-followup@​perl\.org wrote​: :rt.perl.org 24691 is about CPAN.pm saying that a path with a leading space :is not absolute. The issue is File​::Spec... maybe. file_name_is_absolute() i :does not recognize " /foo" as being absolute. : :$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute(" /foo")' : :$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute("/foo")' :1 : :canonpath() does not clean up leading or trailing space. : :$ perl -wle 'use File​::Spec; print File​::Spec->canonpath("/foo")' :/foo : :$ perl -wle 'use File​::Spec; print File​::Spec->canonpath(" /foo")' : /foo :$ perl -wle 'use File​::Spec; print q["].File​::Spec->canonpath(" /foo ").q["]' :" /foo " : :Should it? Does leading and trailing space have any meaning in a Unix path?

Yes​: I can happily create and act on files and directories with spaces (even consisting only of spaces) as long as I protect them from the shell. This seems perfectly correct to me.

As far as I know a unix directory entry is one or more characters in the range \x1..\xff excluding '/'\, no other restrictions except for maximum length.

Hugo

p5pRT commented 19 years ago

From @schwern

Ok then\, I'll close this ticket up.

p5pRT commented 19 years ago

@schwern - Status changed from 'open' to 'resolved'

p5pRT commented 19 years ago

From @kenahoo

On Jul 12\, 2005\, at 1​:40 AM\, Michael G Schwern wrote​:

rt.perl.org 24691 is about CPAN.pm saying that a path with a leading space is not absolute. The issue is File​::Spec... maybe.
file_name_is_absolute() i does not recognize " /foo" as being absolute.

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute(" /foo")'

$ perl -wle 'use File​::Spec; print File​::Spec->file_name_is_absolute("/foo")' 1

canonpath() does not clean up leading or trailing space.

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath("/foo")' /foo

$ perl -wle 'use File​::Spec; print File​::Spec->canonpath(" /foo")' /foo $ perl -wle 'use File​::Spec; print q["].File​::Spec->canonpath(" /foo ").q["]' " /foo "

Should it? Does leading and trailing space have any meaning in a Unix path?

The current behavior is correct. The space is just like any other filename. " /foo" is a file (or possibly a directory) called "foo" in a directory called " ".

  -Ken