Feature #3185

File.expand_path repeats forward slashes at the beginning of the path

Added by Brian Shirai about 5 years ago. Updated about 4 years ago.

[ruby-core:29710]
Status:Rejected
Priority:Normal
Assignee:-

Description

=begin
When File.expand_path is passed a string with multiple consecutive forward slashes, it preserves them in the output. This would appear to be a bug since everywhere else in the path, consecutive separators are collapsed to a single one.

$ ruby1.8.7 -v -e 'p File.expand_path("//////some/dir")'
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]
"//////some/dir"

$ ruby1.8.7 -v -e 'p File.expand_path("//////some/dir", "/Foo")'
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]
"//////some/dir"

The same behavior exists on 1.9.

$ ruby1.9 -v -e 'p File.expand_path("//////some/dir")'
ruby 1.9.2dev (2010-03-30 trunk 27097) [i386-darwin9.8.0]
"//////some/dir"
$ ruby1.9 -v -e 'p File.expand_path("//////some/dir", "/Foo")'
ruby 1.9.2dev (2010-03-30 trunk 27097) [i386-darwin9.8.0]
"//////some/dir"

Thanks,
Brian
=end

History

#1 Updated by ujihisa . about 5 years ago

=begin
I'm not sure which is desirable behavior; eliminating repeated slashes or preserving them, but I wrote the patch.

$ ruby192 -ve 'p File.expand_path("//////some/dir")'
ruby 1.9.2dev (2010-04-27 trunk 27505) [i386-darwin9.8.0]
"/some/dir"
$ ruby192 -ve 'p File.expand_path("//////some/dir", "/Foo")'
ruby 1.9.2dev (2010-04-27 trunk 27505) [i386-darwin9.8.0]
"/some/dir"

Also, this patch passes make test and the corresponding RubySpec.

$ mspec -t ruby192 core/file/expand_path_spec.rb
uby 1.9.2dev (2010-04-27 trunk 27505) [i386-darwin9.8.0]
................

Finished in 0.016287 seconds

1 file, 16 examples, 45 expectations, 0 failures, 0 errors
=end

#2 Updated by ujihisa . about 5 years ago

=begin
Oops. Forgot to attach the patch or failed to upload it. trying again.
=end

#3 Updated by Nobuyoshi Nakada about 5 years ago

  • Status changed from Open to Rejected

=begin
Intended.
I've heard that some kinds of network file systems use // to designate external directories.
=end

#4 Updated by ujihisa . about 5 years ago

=begin
Thx. I just fixed the corresponding RubySpec. http://github.com/rubyspec/rubyspec/commit/40eedde8d44ca8a34e80ea1e5d7d23e19f3e2bda
=end

#5 Updated by Usaku NAKAMURA about 5 years ago

=begin
Hello,

In message " Bug #3185 File.expand_path repeats forward slashes at the beginning of the path"
on Apr.27,2010 08:32:09, redmine@ruby-lang.org wrote:

Issue #3185 has been updated by Nobuyoshi Nakada.

Status changed from Open to Rejected

Intended.
I've heard that some kinds of network file systems use // to designate external directories.

It is necessary to consider UNC only in the environment that
supports it.
Actually, rubyspec excludes Windows from the test case.

Regards,
--
U.Nakamura usa@garbagecollect.jp

=end

#6 Updated by Brian Shirai about 5 years ago

=begin
Could we please get clarification on when it is required and on what platforms? Just allowing an unlimited number of forward slashes seems unreasonable.

Thanks,
Brian
=end

#7 Updated by Ryan Davis about 5 years ago

=begin

On Apr 26, 2010, at 21:22 , Brian Ford wrote:

Issue #3185 has been updated by Brian Ford.

Could we please get clarification on when it is required and on what platforms? Just allowing an unlimited number of forward slashes seems unreasonable.

Seems reasonable to me and allows for things like this to be clean and easy:

URI.parse "file:" + File.expand_path('//path/to/../file.txt')
=> #

=end

#8 Updated by Brian Shirai about 5 years ago

=begin
On Tue, Apr 27, 2010 at 2:48 PM, Ryan Davis ryand-ruby@zenspider.com wrote:

On Apr 26, 2010, at 21:22 , Brian Ford wrote:

Issue #3185 has been updated by Brian Ford.

Could we please get clarification on when it is required and on what platforms? Just allowing an unlimited number of forward slashes seems unreasonable.

Seems reasonable to me and allows for things like this to be clean and easy:

URI.parse "file:" + File.expand_path('//path/to/../file.txt')
=> #

That's two, not an arbitrary number.

URI.parse "file:/" + File.expand_path('/path/to/../file.txt') is no less simple.

=end

#9 Updated by Yui NARUSE about 5 years ago

=begin
(2010/04/28 17:02), brian ford wrote:

On Tue, Apr 27, 2010 at 2:48 PM, Ryan Davisryand-ruby@zenspider.com wrote:

On Apr 26, 2010, at 21:22 , Brian Ford wrote:

Issue #3185 has been updated by Brian Ford.

Could we please get clarification on when it is required and on what platforms? Just allowing an unlimited number of forward slashes seems unreasonable.

Seems reasonable to me and allows for things like this to be clean and easy:

URI.parse "file:" + File.expand_path('//path/to/../file.txt')
=> #

That's two, not an arbitrary number.

URI.parse "file:/" + File.expand_path('/path/to/../file.txt') is no less simple.

This must be:
* file:///path/to/../file.txt
* file://localhost/C:/foo/bar/baz.txt

 URI           = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
 hier-part     = "//" authority path-abempty
               / path-absolute
               / path-rootless
               / path-empty

http://tools.ietf.org/html/rfc3986

So the problem is, what is the argument of File.expand_path.

http://en.wikipedia.org/wiki/Path_(computing)#Posix_pathname_definition

--
NARUSE, Yui naruse@airemix.jp

=end

Also available in: Atom PDF