ruby-changes:47360
From: nobu <ko1@a...>
Date: Thu, 3 Aug 2017 11:14:57 +0900 (JST)
Subject: [ruby-changes:47360] nobu:r59476 (trunk): dir.c: relax base option
nobu 2017-08-03 11:14:51 +0900 (Thu, 03 Aug 2017) New Revision: 59476 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59476 Log: dir.c: relax base option * dir.c (dir_glob_options): relax base option. ignore when nil or an empty string as :base option. [Feature #13056] Modified files: trunk/dir.c trunk/test/ruby/test_dir.rb Index: dir.c =================================================================== --- dir.c (revision 59475) +++ dir.c (revision 59476) @@ -2466,7 +2466,7 @@ dir_glob_options(VALUE opt, VALUE *base, https://github.com/ruby/ruby/blob/trunk/dir.c#L2466 kw[0] = rb_intern("base"); if (flags) kw[1] = rb_intern("flags"); rb_get_kwargs(opt, kw, 0, flags ? 2 : 1, args); - if (args[0] == Qundef) { + if (args[0] == Qundef || NIL_P(args[0])) { *base = Qnil; } #if USE_OPENDIR_AT @@ -2476,6 +2476,7 @@ dir_glob_options(VALUE opt, VALUE *base, https://github.com/ruby/ruby/blob/trunk/dir.c#L2476 #endif else { GlobPathValue(args[0], TRUE); + if (!RSTRING_LEN(args[0])) args[0] = Qnil; *base = args[0]; } if (flags && args[1] != Qundef) { Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 59475) +++ test/ruby/test_dir.rb (revision 59476) @@ -206,6 +206,9 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L206 files = %w[a/foo.c c/bar.c] files.each {|n| File.write(File.join(@root, n), "")} assert_equal(files, Dir.glob("*/*.c", base: @root).sort) + assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: ".").sort}) + assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: "").sort}) + assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: nil).sort}) end def test_glob_base_dir -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/