[前][次][番号順一覧][スレッド一覧]

ruby-changes:74216

From: nagachika <ko1@a...>
Date: Sun, 23 Oct 2022 19:41:25 +0900 (JST)
Subject: [ruby-changes:74216] ffa439fd29 (ruby_3_1): merge revision(s) 329d5424a479bb08e75bd750c51a5382e382731c: [Backport #19042]

https://git.ruby-lang.org/ruby.git/commit/?id=ffa439fd29

From ffa439fd29141626878f4c4b56e86b2fee17294e Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sun, 23 Oct 2022 19:14:08 +0900
Subject: 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@r...>
	---
	 dir.c                 |  2 +-
	 test/ruby/test_dir.rb | 14 ++++++++++++++
	 2 files changed, 15 insertions(+), 1 deletion(-)
---
 dir.c                 |  2 +-
 test/ruby/test_dir.rb | 14 ++++++++++++++
 version.h             |  2 +-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index 184dbf007e..1b651904a9 100644
--- a/dir.c
+++ b/dir.c
@@ -2295,7 +2295,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L2295
 #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 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]"))
diff --git a/version.h b/version.h
index dc042bbf9d..05a2988eab 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L11
 # 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
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]