mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
range.c (inspect_range): omit beginless "nil"
except the special case `(nil..nil)`. ``` (1..).inspect #=> "1.." (..5).inspect #=> "..5" (nil..nil).inspect #=> "nil..nil" ``` [Bug #15745]
This commit is contained in:
parent
d9b338a53f
commit
9d39eb6b40
2 changed files with 13 additions and 3 deletions
12
range.c
12
range.c
|
@ -1317,10 +1317,16 @@ inspect_range(VALUE range, VALUE dummy, int recur)
|
||||||
if (recur) {
|
if (recur) {
|
||||||
return rb_str_new2(EXCL(range) ? "(... ... ...)" : "(... .. ...)");
|
return rb_str_new2(EXCL(range) ? "(... ... ...)" : "(... .. ...)");
|
||||||
}
|
}
|
||||||
str = rb_inspect(RANGE_BEG(range));
|
if (!NIL_P(RANGE_BEG(range)) || NIL_P(RANGE_END(range))) {
|
||||||
if (!NIL_P(RANGE_END(range))) str2 = rb_inspect(RANGE_END(range));
|
str = rb_str_dup(rb_inspect(RANGE_BEG(range)));
|
||||||
str = rb_str_dup(str);
|
}
|
||||||
|
else {
|
||||||
|
str = rb_str_new(0, 0);
|
||||||
|
}
|
||||||
rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
|
rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
|
||||||
|
if (NIL_P(RANGE_BEG(range)) || !NIL_P(RANGE_END(range))) {
|
||||||
|
str2 = rb_inspect(RANGE_END(range));
|
||||||
|
}
|
||||||
if (str2 != Qundef) rb_str_append(str, str2);
|
if (str2 != Qundef) rb_str_append(str, str2);
|
||||||
OBJ_INFECT(str, range);
|
OBJ_INFECT(str, range);
|
||||||
|
|
||||||
|
|
|
@ -489,6 +489,10 @@ class TestRange < Test::Unit::TestCase
|
||||||
assert_equal("0...1", (0...1).inspect)
|
assert_equal("0...1", (0...1).inspect)
|
||||||
assert_equal("0..", (0..nil).inspect)
|
assert_equal("0..", (0..nil).inspect)
|
||||||
assert_equal("0...", (0...nil).inspect)
|
assert_equal("0...", (0...nil).inspect)
|
||||||
|
assert_equal("..1", (nil..1).inspect)
|
||||||
|
assert_equal("...1", (nil...1).inspect)
|
||||||
|
assert_equal("nil..nil", (nil..nil).inspect)
|
||||||
|
assert_equal("nil...nil", (nil...nil).inspect)
|
||||||
|
|
||||||
bug11767 = '[ruby-core:71811] [Bug #11767]'
|
bug11767 = '[ruby-core:71811] [Bug #11767]'
|
||||||
assert_predicate(("0".taint.."1").inspect, :tainted?, bug11767)
|
assert_predicate(("0".taint.."1").inspect, :tainted?, bug11767)
|
||||||
|
|
Loading…
Reference in a new issue