ruby-changes:54623
From: shirosaki <ko1@a...>
Date: Wed, 16 Jan 2019 23:06:43 +0900 (JST)
Subject: [ruby-changes:54623] shirosaki:r66838 (trunk): dir.c: fix Dir.glob with braces and matching dir
shirosaki 2019-01-16 23:06:37 +0900 (Wed, 16 Jan 2019) New Revision: 66838 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66838 Log: dir.c: fix Dir.glob with braces and matching dir * dir.c (join_path_from_pattern): add the last slash for directory matching. * test/ruby/test_dir.rb (test_glob_recursive_directory): add a test for above. [ruby-core:91110] [Bug #15540] Modified files: trunk/dir.c trunk/test/ruby/test_dir.rb Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 66837) +++ test/ruby/test_dir.rb (revision 66838) @@ -191,6 +191,20 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L191 end end + def test_glob_recursive_directory + Dir.chdir(@root) do + ['d', 'e'].each do |path| + FileUtils.mkdir_p("c/#{path}/a/b/c") + FileUtils.touch("c/#{path}/a/a.file") + FileUtils.touch("c/#{path}/a/b/b.file") + FileUtils.touch("c/#{path}/a/b/c/c.file") + end + bug15540 = '[ruby-core:91110] [Bug #15540]' + assert_equal(["c/d/a/", "c/d/a/b/", "c/d/a/b/c/", "c/e/a/", "c/e/a/b/", "c/e/a/b/c/"], + Dir.glob('c/{d,e}/a/**/'), bug15540) + end + end + if Process.const_defined?(:RLIMIT_NOFILE) def test_glob_too_may_open_files assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}", chdir: @root) Index: dir.c =================================================================== --- dir.c (revision 66837) +++ dir.c (revision 66838) @@ -2052,6 +2052,10 @@ join_path_from_pattern(struct glob_patte https://github.com/ruby/ruby/blob/trunk/dir.c#L2052 case RECURSIVE: str = "**"; break; + case MATCH_DIR: + /* append last slash */ + str = ""; + break; default: str = p->str; if (!str) continue; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/