ruby-changes:74069
From: Hiroshi <ko1@a...>
Date: Tue, 18 Oct 2022 11:25:13 +0900 (JST)
Subject: [ruby-changes:74069] 329d5424a4 (master): [Bug #19042] Fix Dir.glob brace with '/'
https://git.ruby-lang.org/ruby.git/commit/?id=329d5424a4 From 329d5424a479bb08e75bd750c51a5382e382731c Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki <h.shirosaki@g...> Date: Tue, 18 Oct 2022 09:18:03 +0900 Subject: [Bug #19042] Fix Dir.glob brace with '/' Dir.glob brace pattern with '/' after '**' does not match paths in recursive expansion process. We expand braces with '/' before expanding a recursive. Co-authored-by: Nobuyoshi Nakada <nobu@r...> --- dir.c | 2 +- test/ruby/test_dir.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index a3ea5eea50..a35aace6f1 100644 --- a/dir.c +++ b/dir.c @@ -2305,7 +2305,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L2305 #endif break; case BRACE: - if (!recursive) { + if (!recursive || strchr(p->str, '/')) { brace = 1; } break; diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index 514c6e5921..ebbed75445 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -259,6 +259,20 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L259 end end + def test_glob_recursive_with_brace + Dir.chdir(@root) do + bug19042 = '[ruby-core:110220] [Bug #19042]' + %w"c/dir_a c/dir_b c/dir_b/dir".each do |d| + Dir.mkdir(d) + end + expected = %w"c/dir_a/file c/dir_b/dir/file" + expected.each do |f| + File.write(f, "") + end + assert_equal(expected, Dir.glob("**/{dir_a,dir_b/dir}/file"), bug19042) + end + end + def test_glob_order Dir.chdir(@root) do assert_equal(["#{@root}/a", "#{@root}/b"], Dir.glob("#{@root}/[ba]")) -- cgit v1.2.3 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/