mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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@ruby-lang.org>
This commit is contained in:
parent
995bdd69de
commit
329d5424a4
2 changed files with 15 additions and 1 deletions
2
dir.c
2
dir.c
|
@ -2305,7 +2305,7 @@ glob_helper(
|
|||
#endif
|
||||
break;
|
||||
case BRACE:
|
||||
if (!recursive) {
|
||||
if (!recursive || strchr(p->str, '/')) {
|
||||
brace = 1;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -259,6 +259,20 @@ class TestDir < Test::Unit::TestCase
|
|||
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]"))
|
||||
|
|
Loading…
Reference in a new issue