diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-02-09 09:58:05 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2022-02-09 19:47:28 -0800 |
commit | fd710d7e9995679db80b7adf35bbda2cd4db90c6 (patch) | |
tree | b4562df20ddfb4d1a1db40e960f0cebc747f36c4 /range.c | |
parent | 05b1944c53205ffd8c11f1ec2ae6fd48485b55b1 (diff) |
Fix Range#include? for beginless exclusive string ranges
Previously, include? would return true for the end of the range,
when it should return false because the range is exclusive.
Research and Analysis by Victor Shepelev.
Fixes [Bug #18577]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5541
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -1792,6 +1792,9 @@ range_include_internal(VALUE range, VALUE val, int string_use_cover) else if (NIL_P(beg)) { VALUE r = rb_funcall(val, id_cmp, 1, end); if (NIL_P(r)) return Qfalse; + if (RANGE_EXCL(range)) { + return RBOOL(rb_cmpint(r, val, end) < 0); + } return RBOOL(rb_cmpint(r, val, end) <= 0); } else if (NIL_P(end)) { |