summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--range.c11
-rw-r--r--test/ruby/test_range.rb10
2 files changed, 18 insertions, 3 deletions
diff --git a/range.c b/range.c
index 68264992f37..422ed29f151 100644
--- a/range.c
+++ b/range.c
@@ -1231,14 +1231,19 @@ range_dumper(VALUE range)
static VALUE
range_loader(VALUE range, VALUE obj)
{
+ VALUE beg, end, excl;
+
if (!RB_TYPE_P(obj, T_OBJECT) || RBASIC(obj)->klass != rb_cObject) {
rb_raise(rb_eTypeError, "not a dumped range object");
}
range_modify(range);
- RANGE_SET_BEG(range, rb_ivar_get(obj, id_beg));
- RANGE_SET_END(range, rb_ivar_get(obj, id_end));
- RANGE_SET_EXCL(range, rb_ivar_get(obj, id_excl));
+ beg = rb_ivar_get(obj, id_beg);
+ end = rb_ivar_get(obj, id_end);
+ excl = rb_ivar_get(obj, id_excl);
+ if (!NIL_P(excl)) {
+ range_init(range, beg, end, RBOOL(RTEST(excl)));
+ }
return range;
}
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index a70361d6cb2..1ce3f0663ae 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -110,6 +110,16 @@ class TestRange < Test::Unit::TestCase
assert_nothing_raised { r.instance_eval { initialize 5, 6} }
end
+ def test_marshal
+ r = 1..2
+ assert_equal(r, Marshal.load(Marshal.dump(r)))
+ r = 1...2
+ assert_equal(r, Marshal.load(Marshal.dump(r)))
+ s = Marshal.dump(r)
+ s.sub!(/endi./n, 'end0')
+ assert_raise(ArgumentError) {Marshal.load(s)}
+ end
+
def test_bad_value
assert_raise(ArgumentError) { (1 .. :a) }
end