Bug #8597

Unexpected result of Dir.glob of '<' or '>' on Windows

Added by Heesob Park over 1 year ago. Updated over 1 year ago.

[ruby-core:55764]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 2.1.0dev (2013-07-02 trunk 41732) [i386-mswin32_100] Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

I have found the following results of Dir.glob when containing '<' or '>' on path.

C:\Users\phasis>irb
irb(main):001:0> Dir.glob('>')
=> [">"]
irb(main):002:0> Dir.glob('<')
=> ["<"]
irb(main):003:0> Dir.glob('>><<>><<')
=> [">><<>><<"]
irb(main):004:0> Dir.glob('>>.<<')
=> [">>.<<"]
irb(main):005:0> Dir.glob('<><>.<><>')
=> ["<><>.<><>"]
irb(main):006:0> Dir.glob('a<<<')
=> ["a<<<"]
irb(main):007:0> Dir.glob('.<<<')
=> [".<<<"]
irb(main):008:0> Dir.glob('>>.rb')
=> [">>.rb"]

These results are due to a bug of stat function of Windows.

I think it would be better to raise Invalid argument error like File.stat.

irb(main):010:0> File.stat('>>.rb')
Errno::EINVAL: Invalid argument @ rb_file_s_stat - >>.rb
from (irb):10:in stat'
from (irb):10
from c:/usr/bin/irb.bat:18:in
'

Associated revisions

Revision 41755
Added by Nobuyoshi Nakada over 1 year ago

dir.c: get rid of FindFirstFile bug

  • dir.c (do_stat): use rb_w32_ustati64() in win32.c to get rid of mysterious behavior of FindFirstFile() Windows API which treat "<" and ">" like as wildcard characters. [Bug #8597]

Revision 41755
Added by Nobuyoshi Nakada over 1 year ago

dir.c: get rid of FindFirstFile bug

  • dir.c (do_stat): use rb_w32_ustati64() in win32.c to get rid of mysterious behavior of FindFirstFile() Windows API which treat "<" and ">" like as wildcard characters. [Bug #8597]

Revision 49537
Added by Nobuyoshi Nakada about 2 months ago

dir.c: long path name on Windows

  • dir.c (has_magic): always get long path name on Windows even if no tilde is there. [Bug #10819]
  • dir.c (replace_real_basename): FindFirstFile ignore redirection character, check if exists before call it. cf. [Bug #8597]

Revision 49656
Added by Yui NARUSE about 1 month ago

merge revision(s) 49478,49536,49533,49537: [Backport #10819]

* dir.c (glob_helper): obtain real name with FindFirstFile API
  instead of matchin all entries, on Windows.
   [Bug #10819]

* dir.c (has_magic): always get long path name on Windows even if
  no tilde is there.   [Bug #10819]

* dir.c (replace_real_basename): FindFirstFile ignore redirection
  character, check if exists before call it.  cf. [Bug #8597]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r41755.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


dir.c: get rid of FindFirstFile bug

  • dir.c (do_stat): use rb_w32_ustati64() in win32.c to get rid of mysterious behavior of FindFirstFile() Windows API which treat "<" and ">" like as wildcard characters. [Bug #8597]

Also available in: Atom PDF