diff options
| author | nagachika <nagachika@ruby-lang.org> | 2022-10-23 19:14:08 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2022-10-23 19:14:08 +0900 |
| commit | ffa439fd29141626878f4c4b56e86b2fee17294e (patch) | |
| tree | a37e5483f452819b159b8d3f9e2d4df0bb485dc1 | |
| parent | 941c888b041decb45034572d766120f9be34986e (diff) | |
merge revision(s) 329d5424a479bb08e75bd750c51a5382e382731c: [Backport #19042]
[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>
---
dir.c | 2 +-
test/ruby/test_dir.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
| -rw-r--r-- | dir.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_dir.rb | 14 | ||||
| -rw-r--r-- | version.h | 2 |
3 files changed, 16 insertions, 2 deletions
@@ -2295,7 +2295,7 @@ glob_helper( #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 9474c6e927..39a1dae889 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -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]")) @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 169 +#define RUBY_PATCHLEVEL 170 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 10 |
