Project

General

Profile

Actions

Feature #3185

closed

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

Added by brixen (Brian Shirai) almost 14 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:29710]

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

Actions #1

Updated by ujihisa (Tatsuhiro Ujihisa) almost 14 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

Actions #2

Updated by ujihisa (Tatsuhiro Ujihisa) almost 14 years ago

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

Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 14 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

Actions #5

Updated by usa (Usaku NAKAMURA) almost 14 years ago

=begin
Hello,

In message "[ruby-core:29798] Bug #3185 File.expand_path repeats forward slashes at the beginning of the path"
on Apr.27,2010 08:32:09, 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

=end

Actions #6

Updated by brixen (Brian Shirai) almost 14 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

Actions #7

Updated by zenspider (Ryan Davis) almost 14 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')
=> #<URI::Generic:0x100620d08 URL:file://path/file.txt>

=end

Actions #8

Updated by brixen (Brian Shirai) almost 14 years ago

=begin
On Tue, Apr 27, 2010 at 2:48 PM, Ryan Davis 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')
=> #<URI::Generic:0x100620d08 URL:file://path/file.txt>

That's two, not an arbitrary number.

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

=end

Actions #9

Updated by naruse (Yui NARUSE) almost 14 years ago

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

On Tue, Apr 27, 2010 at 2:48 PM, Ryan Davis 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')
=> #<URI::Generic:0x100620d08 URL:file://path/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

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0