From 73dd7cb8273dda646ea5029c0529c2e187df2444 Mon Sep 17 00:00:00 2001 From: mame Date: Wed, 13 Jun 2018 09:04:32 +0000 Subject: range.c: prohibit `(1..nil)` Now endless range can be created by either a literal `(1..)` or explicit range creation `Range.new(1, nil)`. [Bug #14845] This change is intended for "early failure"; for example, `(1..var).to_a` causes out of memory if `var` is inadvertently nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_range.rb | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index c98b130456..8237e69881 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -13,8 +13,8 @@ class TestRange < Test::Unit::TestCase assert_raise(ArgumentError) { (1.."3") } - assert_equal((0..nil), Range.new(0, nil, false)) - assert_equal((0...nil), Range.new(0, nil, true)) + assert_equal((0..), Range.new(0, nil, false)) + assert_equal((0...), Range.new(0, nil, true)) obj = Object.new def obj.<=>(other) @@ -161,15 +161,15 @@ class TestRange < Test::Unit::TestCase assert_not_equal(r, (1..2)) assert_not_equal(r, (0..2)) assert_not_equal(r, (0...1)) - assert_not_equal(r, (0..nil)) + assert_not_equal(r, (0..)) subclass = Class.new(Range) assert_equal(r, subclass.new(0,1)) - r = (0..nil) + r = (0..) assert_equal(r, r) - assert_equal(r, (0..nil)) + assert_equal(r, (0..)) assert_not_equal(r, 0) - assert_not_equal(r, (0...nil)) + assert_not_equal(r, (0...)) subclass = Class.new(Range) assert_equal(r, subclass.new(0,nil)) end @@ -185,11 +185,11 @@ class TestRange < Test::Unit::TestCase subclass = Class.new(Range) assert_operator(r, :eql?, subclass.new(0,1)) - r = (0..nil) + r = (0..) assert_operator(r, :eql?, r) - assert_operator(r, :eql?, 0..nil) + assert_operator(r, :eql?, 0..) assert_not_operator(r, :eql?, 0) - assert_not_operator(r, :eql?, 0...nil) + assert_not_operator(r, :eql?, 0...) subclass = Class.new(Range) assert_operator(r, :eql?, subclass.new(0,nil)) end @@ -198,8 +198,8 @@ class TestRange < Test::Unit::TestCase assert_kind_of(Integer, (0..1).hash) assert_equal((0..1).hash, (0..1).hash) assert_not_equal((0..1).hash, (0...1).hash) - assert_equal((0..nil).hash, (0..nil).hash) - assert_not_equal((0..nil).hash, (0...nil).hash) + assert_equal((0..).hash, (0..).hash) + assert_not_equal((0..).hash, (0...).hash) end def test_step @@ -380,9 +380,9 @@ class TestRange < Test::Unit::TestCase assert_equal(0, (0..1).begin) assert_equal(1, (0..1).end) assert_equal(1, (0...1).end) - assert_equal(0, (0..nil).begin) - assert_equal(nil, (0..nil).end) - assert_equal(nil, (0...nil).end) + assert_equal(0, (0..).begin) + assert_equal(nil, (0..).end) + assert_equal(nil, (0...).end) end def test_first_last @@ -402,17 +402,17 @@ class TestRange < Test::Unit::TestCase assert_equal("c", ("a"..."c").last) assert_equal(0, (2...0).last) - assert_equal([0, 1, 2], (0..nil).first(3)) - assert_equal(0, (0..nil).first) - assert_equal("a", ("a"..nil).first) + assert_equal([0, 1, 2], (0..).first(3)) + assert_equal(0, (0..).first) + assert_equal("a", ("a"..).first) # XXX: How should (0...).last(3) behave? end def test_to_s assert_equal("0..1", (0..1).to_s) assert_equal("0...1", (0...1).to_s) - assert_equal("0..", (0..nil).to_s) - assert_equal("0...", (0...nil).to_s) + assert_equal("0..", (0..).to_s) + assert_equal("0...", (0...).to_s) bug11767 = '[ruby-core:71811] [Bug #11767]' assert_predicate(("0".taint.."1").to_s, :tainted?, bug11767) @@ -423,8 +423,8 @@ class TestRange < Test::Unit::TestCase def test_inspect 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..).inspect) + assert_equal("0...", (0...).inspect) bug11767 = '[ruby-core:71811] [Bug #11767]' assert_predicate(("0".taint.."1").inspect, :tainted?, bug11767) @@ -435,8 +435,8 @@ class TestRange < Test::Unit::TestCase def test_eqq assert_operator(0..10, :===, 5) assert_not_operator(0..10, :===, 11) - assert_operator(5..nil, :===, 11) - assert_not_operator(5..nil, :===, 0) + assert_operator(5.., :===, 11) + assert_not_operator(5.., :===, 0) end def test_eqq_time -- cgit v1.2.3