[Bug #19533] Fix infinite range inclusion with numeric value
This commit is contained in:
parent
1a149aab77
commit
fb17c833f5
Notes:
git
2023-04-14 01:22:32 +00:00
10
range.c
10
range.c
@ -1789,8 +1789,12 @@ range_string_range_p(VALUE beg, VALUE end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
range_include_fallback(VALUE beg, VALUE end)
|
range_include_fallback(VALUE beg, VALUE end, VALUE val)
|
||||||
{
|
{
|
||||||
|
if (NIL_P(beg) && NIL_P(end)) {
|
||||||
|
if (linear_object_p(val)) return Qtrue;
|
||||||
|
}
|
||||||
|
|
||||||
if (NIL_P(beg) || NIL_P(end)) {
|
if (NIL_P(beg) || NIL_P(end)) {
|
||||||
rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges");
|
rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges");
|
||||||
}
|
}
|
||||||
@ -1828,7 +1832,7 @@ range_string_cover_internal(VALUE range, VALUE val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return range_include_fallback(beg, end);
|
return range_include_fallback(beg, end, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -1846,7 +1850,7 @@ range_include_internal(VALUE range, VALUE val)
|
|||||||
return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
|
return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
|
||||||
}
|
}
|
||||||
|
|
||||||
return range_include_fallback(beg, end);
|
return range_include_fallback(beg, end, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val);
|
static int r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val);
|
||||||
|
@ -579,6 +579,8 @@ class TestRange < Test::Unit::TestCase
|
|||||||
assert_not_operator(0..10, :===, 11)
|
assert_not_operator(0..10, :===, 11)
|
||||||
assert_operator(5..nil, :===, 11)
|
assert_operator(5..nil, :===, 11)
|
||||||
assert_not_operator(5..nil, :===, 0)
|
assert_not_operator(5..nil, :===, 0)
|
||||||
|
assert_operator(nil..10, :===, 0)
|
||||||
|
assert_operator(nil..nil, :===, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_eqq_string
|
def test_eqq_string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user