ruby-changes:40131
From: nobu <ko1@a...>
Date: Thu, 22 Oct 2015 13:16:28 +0900 (JST)
Subject: [ruby-changes:40131] nobu:r52212 (trunk): dir.c: glob brace expansion [Fix GH-1061]
nobu 2015-10-22 13:16:21 +0900 (Thu, 22 Oct 2015) New Revision: 52212 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52212 Log: dir.c: glob brace expansion [Fix GH-1061] * dir.c (ruby_brace_expand): glob brace expansion edge case fix. When there are closing braces '}' before a open brace '{' it must be ignored and considered as literal. [ruby-core:71138] [Bug #11609] Modified files: trunk/ChangeLog trunk/dir.c trunk/test/ruby/test_dir.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52211) +++ ChangeLog (revision 52212) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 22 13:16:19 2015 Guilherme Reis Campos <guilhermekbsa@g...> + + * dir.c (ruby_brace_expand): glob brace expansion edge case fix. + When there are closing braces '}' before a open brace '{' it + must be ignored and considered as literal. + [ruby-core:71138] [Bug #11609] + Thu Oct 22 13:13:49 2015 Nobuyoshi Nakada <nobu@r...> * io.c (argf_next_argv): check ARGV element type, and try Index: dir.c =================================================================== --- dir.c (revision 52211) +++ dir.c (revision 52212) @@ -2041,7 +2041,7 @@ ruby_brace_expand(const char *str, int f https://github.com/ruby/ruby/blob/trunk/dir.c#L2041 if (*p == '{' && nest++ == 0) { lbrace = p; } - if (*p == '}' && --nest <= 0) { + if (*p == '}' && lbrace && --nest == 0) { rbrace = p; break; } Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 52211) +++ test/ruby/test_dir.rb (revision 52212) @@ -150,6 +150,11 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L150 assert_equal([File.join(@root, "a")], Dir.glob(File.join(@root, 'a\\'))) assert_equal(("a".."f").map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort) + + open(File.join(@root, "}}{}"), "wb") {} + open(File.join(@root, "}}a"), "wb") {} + assert_equal(%w(}}{} }}a).map {|f| File.join(@root, f)}, Dir.glob(File.join(@root, '}}{\{\},a}'))) + assert_equal(%w(}}{} }}a b c).map {|f| File.join(@root, f)}, Dir.glob(File.join(@root, '{\}\}{\{\},a},b,c}'))) end def test_glob_recursive -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/