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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
432e6805e1
commit
83a31e9e90
3
dir.c
3
dir.c
@ -2466,7 +2466,7 @@ dir_glob_options(VALUE opt, VALUE *base, int *flags)
|
|||||||
kw[0] = rb_intern("base");
|
kw[0] = rb_intern("base");
|
||||||
if (flags) kw[1] = rb_intern("flags");
|
if (flags) kw[1] = rb_intern("flags");
|
||||||
rb_get_kwargs(opt, kw, 0, flags ? 2 : 1, args);
|
rb_get_kwargs(opt, kw, 0, flags ? 2 : 1, args);
|
||||||
if (args[0] == Qundef) {
|
if (args[0] == Qundef || NIL_P(args[0])) {
|
||||||
*base = Qnil;
|
*base = Qnil;
|
||||||
}
|
}
|
||||||
#if USE_OPENDIR_AT
|
#if USE_OPENDIR_AT
|
||||||
@ -2476,6 +2476,7 @@ dir_glob_options(VALUE opt, VALUE *base, int *flags)
|
|||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
GlobPathValue(args[0], TRUE);
|
GlobPathValue(args[0], TRUE);
|
||||||
|
if (!RSTRING_LEN(args[0])) args[0] = Qnil;
|
||||||
*base = args[0];
|
*base = args[0];
|
||||||
}
|
}
|
||||||
if (flags && args[1] != Qundef) {
|
if (flags && args[1] != Qundef) {
|
||||||
|
@ -206,6 +206,9 @@ class TestDir < Test::Unit::TestCase
|
|||||||
files = %w[a/foo.c c/bar.c]
|
files = %w[a/foo.c c/bar.c]
|
||||||
files.each {|n| File.write(File.join(@root, n), "")}
|
files.each {|n| File.write(File.join(@root, n), "")}
|
||||||
assert_equal(files, Dir.glob("*/*.c", base: @root).sort)
|
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
|
end
|
||||||
|
|
||||||
def test_glob_base_dir
|
def test_glob_base_dir
|
||||||
|
Loading…
x
Reference in New Issue
Block a user