Bug #8006

Dir.glob behaves differently on 1.9.3 and 2.0

Added by Thomas Leitner about 1 year ago. Updated 2 months ago.

[ruby-core:53108]
Status:Closed
Priority:Low
Assignee:Nobuyoshi Nakada
Category:core
Target version:-
ruby -v:ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] Backport:1.9.3: DONTNEED, 2.0.0: DONE

Description

=begin
While testing an application of mine with Ruby 2.0 I came across the following problem with Dir.glob where the pattern FOO/BAR/**/* does not match the directory FOO/BAR anymore because the implicit directories '.' and '..' don't get matched anymore.

Used files:

$ find data/webgen/basicwebsitetemplate/
data/webgen/basicwebsitetemplate/
data/webgen/basicwebsitetemplate/ext
data/webgen/basicwebsitetemplate/ext/init.rb
data/webgen/basicwebsitetemplate/webgen.config
data/webgen/basicwebsitetemplate/src
data/webgen/basicwebsitetemplate/src/.gitignore

With Ruby 1.9.3-p327:

1.9.3-p327 :001 > Dir.glob('data/webgen/basicwebsitetemplate/*/', File::FNMPATHNAME|File::FNMDOTMATCH|File::FNMCASEFOLD)
=> ["data/webgen/basic
websitetemplate/.", "data/webgen/basicwebsitetemplate/ext", "data/webgen/basicwebsitetemplate/ext/.", "data/webgen/basicwebsitetemplate/ext/..", "data/webgen/basicwebsitetemplate/ext/init.rb", "data/webgen/basicwebsitetemplate/..", "data/webgen/basicwebsitetemplate/webgen.config", "data/webgen/basicwebsitetemplate/src", "data/webgen/basicwebsitetemplate/src/.", "data/webgen/basicwebsitetemplate/src/..", "data/webgen/basicwebsite_template/src/.gitignore"]
1.9.3-p327 :003 >

With Ruby 2.0.0-p0:

2.0.0-p0 :001 > Dir.glob('data/webgen/basicwebsitetemplate/*/', File::FNMPATHNAME|File::FNMDOTMATCH|File::FNMCASEFOLD)
=> ["data/webgen/basic
websitetemplate/ext", "data/webgen/basicwebsitetemplate/ext/init.rb", "data/webgen/basicwebsitetemplate/webgen.config", "data/webgen/basicwebsitetemplate/src", "data/webgen/basicwebsite_template/src/.gitignore"]

=end

Associated revisions

Revision 43385
Added by Nobuyoshi Nakada 6 months ago

dir.c: DOTMATCH to current directory

  • dir.c (globhelper): don't skip current directories if FNMDOTMATCH is given. [Bug #8006]

History

#1 Updated by Thomas Leitner about 1 year ago

=begin
After some more experimenting, it seems that the '**' operator doesn't act the same like in 1.9.3:

With Ruby 2.0.0-p0:

2.0.0p0 :017 > Dir.glob('data/webgen/basicwebsitetemplate//', File::FNMDOTMATCH|File::FNMCASEFOLD)
=> ["data/webgen/basicwebsitetemplate/./.", "data/webgen/basicwebsitetemplate/./ext", "data/webgen/basicwebsitetemplate/./..", "data/webgen/basicwebsitetemplate/./webgen.config", "data/webgen/basicwebsitetemplate/./src", "data/webgen/basicwebsitetemplate/ext/.", "data/webgen/basicwebsitetemplate/ext/..", "data/webgen/basicwebsitetemplate/ext/init.rb", "data/webgen/basicwebsitetemplate/../.", "data/webgen/basicwebsitetemplate/../passivesources", "data/webgen/basicwebsitetemplate/../..", "data/webgen/basicwebsitetemplate/../bundletemplatefiles", "data/webgen/basicwebsitetemplate/../basicwebsitetemplate", "data/webgen/basicwebsitetemplate/src/.", "data/webgen/basicwebsitetemplate/src/..", "data/webgen/basicwebsitetemplate/src/.gitignore"]
2.0.0p0 :018 > Dir.glob('data/webgen/basic
websitetemplate/*/', File::FNMDOTMATCH|File::FNMCASEFOLD)
=> ["data/webgen/basic
websitetemplate/ext", "data/webgen/basicwebsitetemplate/ext/init.rb", "data/webgen/basicwebsitetemplate/webgen.config", "data/webgen/basicwebsitetemplate/src", "data/webgen/basicwebsite_template/src/.gitignore"]

=end

#2 Updated by Tomoyuki Chikanaga about 1 year ago

  • Assignee set to Nobuyoshi Nakada

Hi,

r36903 seems related with this issue.
I'm not sure it is intentional change or not.
nakada san, what do you think?

#3 Updated by Thomas Leitner about 1 year ago

=begin
For your information, I have fixed this problem in my code, see the (()).

Would be good, though, to know whether this is intentional or not.

Thanks!
=end

#4 Updated by Nobuyoshi Nakada 6 months ago

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

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


dir.c: DOTMATCH to current directory

  • dir.c (globhelper): don't skip current directories if FNMDOTMATCH is given. [Bug #8006]

#5 Updated by Nobuyoshi Nakada 6 months ago

  • Backport set to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#6 Updated by Tomoyuki Chikanaga 2 months ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONE

r43385 was backported to uby20_0 branch at r44897.

Also available in: Atom PDF