summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--dir.c4
-rw-r--r--test/ruby/test_dir.rb14
3 files changed, 22 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b66d141124..6cf62f9427 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/dir.c b/dir.c
index 1dc54dce66..1a375ea85d 100644
--- a/dir.c
+++ b/dir.c
@@ -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) {
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index e385072eec..21902298c0 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -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