1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

dir.c: not skip dot directories if matching

* dir.c (glob_helper): should skip dot directories only for recursion,
  but should not if matching to the given pattern.  [ruby-core:54387]
  [Bug #8283]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-04-18 07:20:53 +00:00
parent c3db44dc35
commit a4188556d3
3 changed files with 17 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Thu Apr 18 16:20:51 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c (glob_helper): should skip dot directories only for recursion,
but should not if matching to the given pattern. [ruby-core:54387]
[Bug #8283]
Thu Apr 18 16:20:21 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* pack.c (pack_unpack): increase buffer size to fix buffer overflow,

6
dir.c
View file

@ -1434,9 +1434,6 @@ glob_helper(
IF_HAVE_HFS(VALUE utf8str = Qnil);
if (recursive && dp->d_name[0] == '.') {
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
if (!(flags & FNM_DOTMATCH)) continue;
/* always skip current and parent directories not to recurse infinitely */
if (!dp->d_name[1]) continue;
if (dp->d_name[1] == '.' && !dp->d_name[2]) continue;
@ -1461,7 +1458,8 @@ glob_helper(
break;
}
name = buf + pathlen + (dirsep != 0);
if (recursive) {
if (recursive && ((flags & FNM_DOTMATCH) || dp->d_name[0] != '.')) {
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
#ifndef _WIN32
if (do_lstat(buf, &st, flags) == 0)
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;

View file

@ -177,6 +177,15 @@ class TestDir < Test::Unit::TestCase
assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/?/e/f"), bug6977)
assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/**/d/e/f"), bug6977)
assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/**/d/e/f"), bug6977)
bug8283 = '[ruby-core:54387] [Bug #8283]'
dirs = ["a/.x", "a/b/.y"]
FileUtils.mkdir_p(dirs)
dirs.map {|dir| open("#{dir}/z", "w") {}}
assert_equal([], Dir.glob("a/**/z").sort, bug8283)
assert_equal(["a/.x/z"], Dir.glob("a/**/.x/z"), bug8283)
assert_equal(["a/.x/z"], Dir.glob("a/.x/**/z"), bug8283)
assert_equal(["a/b/.y/z"], Dir.glob("a/**/.y/z"), bug8283)
end
end