Fix regression when testing inclusion in unbounded ranges

Caused by 04a92a6764.  This treats
unbounded ranges of arbitrary objects the same as how unbounded
string ranges are treated:

  (..x)  === y  # (y <=> x) <= 0
  (...x) === y  # (y <=> x) <  0
  (x..)  === y  # (x <=> y) <= 0

Fixes [Bug #19864]
This commit is contained in:
Jeremy Evans 2023-09-15 16:58:26 -07:00
parent 8835ca23c1
commit 25711683e8
2 changed files with 32 additions and 0 deletions

View file

@ -1820,6 +1820,7 @@ range_string_cover_internal(VALUE range, VALUE val)
return r_cover_p(range, beg, end, val);
}
if (NIL_P(beg)) {
unbounded_begin:;
VALUE r = rb_funcall(val, id_cmp, 1, end);
if (NIL_P(r)) return Qfalse;
if (RANGE_EXCL(range)) {
@ -1828,12 +1829,20 @@ range_string_cover_internal(VALUE range, VALUE val)
return RBOOL(rb_cmpint(r, val, end) <= 0);
}
else if (NIL_P(end)) {
unbounded_end:;
VALUE r = rb_funcall(beg, id_cmp, 1, val);
if (NIL_P(r)) return Qfalse;
return RBOOL(rb_cmpint(r, beg, val) <= 0);
}
}
if (!NIL_P(beg) && NIL_P(end)) {
goto unbounded_end;
}
if (NIL_P(beg) && !NIL_P(end)) {
goto unbounded_begin;
}
return range_include_fallback(beg, end, val);
}