ruby-changes:24854
From: nobu <ko1@a...>
Date: Wed, 5 Sep 2012 13:30:21 +0900 (JST)
Subject: [ruby-changes:24854] nobu:r36905 (trunk): dir.c: fix recursion
nobu 2012-09-05 13:30:10 +0900 (Wed, 05 Sep 2012) New Revision: 36905 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36905 Log: dir.c: fix recursion * dir.c (glob_make_pattern): names under recursive need to be single basenames to match for each name. [ruby-core:47418] [Bug #6977] Modified files: trunk/ChangeLog trunk/dir.c trunk/test/ruby/test_dir.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36904) +++ ChangeLog (revision 36905) @@ -1,3 +1,8 @@ +Wed Sep 5 13:30:04 2012 Nobuyoshi Nakada <nobu@r...> + + * dir.c (glob_make_pattern): names under recursive need to be single + basenames to match for each name. [ruby-core:47418] [Bug #6977] + Tue Sep 4 20:55:17 2012 Hiroshi Shirosaki <h.shirosaki@g...> * test/ruby/envutil.rb (EnvUtil#invoke_ruby): show Timeout::Error Index: dir.c =================================================================== --- dir.c (revision 36904) +++ dir.c (revision 36905) @@ -1171,6 +1171,7 @@ { struct glob_pattern *list, *tmp, **tail = &list; int dirsep = 0; /* pattern is terminated with '/' */ + int recursive = 0; while (p < e && *p) { tmp = GLOB_ALLOC(struct glob_pattern); @@ -1181,13 +1182,14 @@ tmp->type = RECURSIVE; tmp->str = 0; dirsep = 1; + recursive = 1; } else { const char *m = find_dirsep(p, e, flags, enc); int magic = has_magic(p, m, flags, enc); char *buf; - if (!magic && *m) { + if (!magic && !recursive && *m) { const char *m2; while (!has_magic(m+1, m2 = find_dirsep(m+1, e, flags, enc), flags, enc) && *m2) { Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 36904) +++ test/ruby/test_dir.rb (revision 36905) @@ -166,6 +166,20 @@ assert_equal((?a..?f).map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort) end + def test_glob_recursive + bug6977 = '[ruby-core:47418]' + Dir.chdir(@root) do + FileUtils.mkdir_p("a/b/c/d/e/f") + assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/e/f"), bug6977) + assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/d/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/**/b/c/d/e/f"), bug6977) + 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) + end + end + def test_foreach assert_equal(Dir.foreach(@root).to_a.sort, %w(. ..) + (?a..?z).to_a) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/