mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
range.c: check loading
* range.c (range_loader): check loading values if the data came from an initialized range object. [ruby-core:78067] [Bug #12915] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e41ebc50dc
commit
54bc0a446d
2 changed files with 18 additions and 3 deletions
11
range.c
11
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue