Forum: Ruby-core [ruby-trunk - Bug #7374][Open] File.expand_path resolving to first file/dir instead of absolute path

Posted by "mdube@arcane-technologies.com (Martin Dubé)" <mdu (Guest)
on 2012-11-16 19:23
(Received via mailing list)
Issue #7374 has been reported by mdube@arcane-technologies.com (Martin 
Dubé).

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by "mdube@arcane-technologies.com (Martin Dubé)" <mdu (Guest)
on 2012-11-16 19:32
(Received via mailing list)
Issue #7374 has been updated by mdube@arcane-technologies.com (Martin 
Dubé).


ruby 1.9.3p194 (2012-04-20) [i386-mingw32] is working fine:

irb(main):002:0> File.expand_path("./*", "c:/temp")
=> "c:/temp/*"

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32988

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-16 22:32
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).

Category set to core
Status changed from Open to Assigned
Assignee set to h.shirosaki (Hiroshi Shirosaki)

Martin,

Can you confirm if this happen with Ruby 2.0? (trunk, you can get 
automated builds from RubyInstaller CI)

Shirosaki-san,

Seems that globing has been enabled?

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32991

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: Normal
Assignee: h.shirosaki (Hiroshi Shirosaki)
Category: core
Target version:
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-16 23:11
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).

Assignee changed from h.shirosaki (Hiroshi Shirosaki) to luislavena 
(Luis Lavena)
Priority changed from Normal to High
Target version set to 2.0.0

=begin
I can confirm this happens on both 1.9.3-p327 and trunk.

Problem seems to be related to replace_to_long_name which attempts to 
expand the last part of the path using FindFirstFileW (globing), but is 
ignoring that it includes "*" in the filename.

I'm checking this and adding a test for this scenario.

Thank you for your report.
=end
----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32992

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by "mdube@arcane-technologies.com (Martin Dubé)" <mdu (Guest)
on 2012-11-16 23:19
(Received via mailing list)
Issue #7374 has been updated by mdube@arcane-technologies.com (Martin 
Dubé).


luislavena (Luis Lavena) wrote:
> Martin,
>
> Can you confirm if this happen with Ruby 2.0? (trunk, you can get automated 
builds from RubyInstaller CI)
>
> Shirosaki-san,
>
> Seems that globing has been enabled?

Yes, same problem with r37691:

C:\ruby-2.0.0-r37691-i386-mingw32\bin>irb.bat
irb(main):001:0> File.expand_path("./*", "c:/")
=> "c:/$RECYCLE.BIN"
irb(main):002:0>

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32993

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-16 23:22
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).


Martin,

I'm adding tests for this, do you have any other scenario that is 
failing and you want to report?

It will be great if we can cover all those by a single commit.

Thank you.
----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32994

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by "mdube@arcane-technologies.com (Martin Dubé)" <red (Guest)
on 2012-11-16 23:31
(Received via mailing list)
Issue #7374 has been updated by mdube@arcane-technologies.com (Martin 
Dubé).


=begin
No other scenario.  Caught that bug trying to install a plugin to 
redmine 2.1.2 with ruby 1.9.3p327

Redmine then attempt to add plugins routes with the following code:

(({Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|}))

Which end up enumerating only the "." directory instead of all 
subdirectories in ./plugins
=end

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32995

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-16 23:55
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).


Martin,

I've committed some tests and a fix for this.

Automated builds will kick in soon, please check RubyInstaller CI to 
download binary packages.

I'll request a backport once I get confirmation this works on your end.

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-32997

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Closed
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by h.shirosaki (Hiroshi Shirosaki) (Guest)
on 2012-11-17 02:05
(Received via mailing list)
Issue #7374 has been updated by h.shirosaki (Hiroshi Shirosaki).

Status changed from Closed to Assigned

It seems if the last part of the path contains * or ?, FindFirstFileW 
should not be used since FindFirstFileW expands wildcard.

Examples:
File.expand_path("foo/ab*c")
File.expand_path("foo/ab?c")

Code in file.c uses strpbrk(s, "*?") for that.
https://github.com/ruby/ruby/blob/trunk/file.c#L3141
----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-33000

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-17 13:36
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).

% Done changed from 100 to 50

h.shirosaki (Hiroshi Shirosaki) wrote:
> It seems if the last part of the path contains * or ?, FindFirstFileW should not 
be used since FindFirstFileW expands wildcard.
>

Thank you Shirosaki, I did a naive fix and completely missed "?" 
character.

Will modify replace_to_long_name to check for this.

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-33021

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-17 16:55
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).

Status changed from Closed to Assigned
% Done changed from 100 to 90

=begin
Sorry for the noise, but seems I've a Webrick failure caused by this 
that didn't catch when sent r37700 in.

 test_short_filename(WEBrick::TestFileHandler) 
[C:/Users/Worker/Jenkins/workspace/ruby-trunk-x86-build/test/webrick/test_filehandler.rb:240]:
 webrick log start:
   [2012-11-17 12:49:00] INFO  WEBrick 1.3.1
   [2012-11-17 12:49:00] INFO  ruby 2.0.0 (2012-11-17) [i386-mingw32]
   [2012-11-17 12:49:00] INFO  WEBrick::HTTPServer#start: pid=14444 
port=62527

   [2012-11-17 12:49:00] WARN  the request refers nondisclosure name 
`.htaccess'.
   [2012-11-17 12:49:00] ERROR `/.htaccess' not found.


 webrick log end.
 <"404"> expected but was
 <"200">.

Looking into this right now.
=end

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-33024

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Assigned
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Posted by Luis Lavena (luislavena)
on 2012-11-17 19:04
(Received via mailing list)
Issue #7374 has been updated by luislavena (Luis Lavena).


Martin, Hiroshi,

This should be finally fixed by r37706, sorry for all the 
inconveniences!

(note to myself: don't commit to Ruby on during night, even less on 
friday).

----------------------------------------
Bug #7374: File.expand_path resolving to first file/dir instead of 
absolute path
https://bugs.ruby-lang.org/issues/7374#change-33026

Author: mdube@arcane-technologies.com (Martin Dubé)
Status: Closed
Priority: High
Assignee: luislavena (Luis Lavena)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32]


=begin
(({File.expand_path("./*", "c:)"}))
will give "c:/$recycle.bin" as result instead of "c:/*"

(({File.expand_path("./*", "c:/temp)"}))
will give "c:/temp/." as result instead of "c:/temp/*"

It looks like the first directory entry is returned instead of the 
absolute path.


=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.