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

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-09-05 04:30:10 +00:00
parent f1df537a83
commit 83185f9181
3 changed files with 22 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Wed Sep 5 13:30:04 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@gmail.com>
* test/ruby/envutil.rb (EnvUtil#invoke_ruby): show Timeout::Error

4
dir.c
View file

@ -1171,6 +1171,7 @@ glob_make_pattern(const char *p, const char *e, int flags, rb_encoding *enc)
{
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 @@ glob_make_pattern(const char *p, const char *e, int flags, rb_encoding *enc)
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) {

View file

@ -166,6 +166,20 @@ class TestDir < Test::Unit::TestCase
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