Issue #11609 has been updated by Guilherme Reis Campos.

Subject changed from Dir.glob brace expansion edge case that don't work properly to Dir.glob brace expansion  possible edge case 

----------------------------------------
Bug #11609: Dir.glob brace expansion  possible edge case 
https://bugs.ruby-lang.org/issues/11609#change-54510

* Author: Guilherme Reis Campos
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v: 2.3.0-dev
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I found an edge case of Dir.glob that don't work properly.

It may not work in any version.  I discovered it after spelunking through: ruby_brace_expand function on dir.c (https://github.com/ruby/ruby/blob/trunk/dir.c#L2030) (as you may  look: if you add lots of '}' the nest variable won't get to 0 it will be less than zero, so it would not get into the if (lbrace && rbrace) that parses the glob, that's the clue i have.).


Below, the output of the script and a zsh glob expansion (that works).

output:

~~~
  test-ruby  ruby test_dir.rb                                                                                        
expected: ["/private/var/folders/t6/bd6y26k14wb3y25xj3m2mc700000gn/T/__test_dir__20151021-45314-1u78o68/}}{}", "/private/var/folders/t6/bd6y26k14wb3y25xj3m2mc700000gn/T/__test_dir__20151021-45314-1u78o68/}}a"]
got: []
  test-ruby  ls /private/var/folders/t6/bd6y26k14wb3y25xj3m2mc700000gn/T/__test_dir__20151021-45314-1u78o68/}}{\{\},a}
/private/var/folders/t6/bd6y26k14wb3y25xj3m2mc700000gn/T/__test_dir__20151021-45314-1u78o68/}}a
/private/var/folders/t6/bd6y26k14wb3y25xj3m2mc700000gn/T/__test_dir__20151021-45314-1u78o68/}}{}
~~~

I've made a pull request with a possible solution: https://github.com/ruby/ruby/pull/1061

---Files--------------------------------
test_dir.rb (383 Bytes)


-- 
https://bugs.ruby-lang.org/