diff options
author | Jeremy Evans <[email protected]> | 2023-09-15 16:58:26 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2023-09-16 16:02:31 +0100 |
commit | 25711683e86271385e8abe09a9c03782000e48db (patch) | |
tree | a098c740667e40cc626562abb365f5e74c3324cc /range.c | |
parent | 8835ca23c138b2fa5e883acd6b368fdc25d7ce23 (diff) |
Fix regression when testing inclusion in unbounded ranges
Caused by 04a92a6764bf678919cf4b68a27496a39d6b886a. 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]
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -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); } |