diff options
| author | NARUSE, Yui <nurse@users.noreply.github.com> | 2024-03-22 10:33:40 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-22 01:33:40 +0000 |
| commit | 6d6818883b8f613fe9b6c72ac7eb9b313bba097b (patch) | |
| tree | b736dd325ffe1eddb32119810fcfa9ec2c0229db | |
| parent | a24802e8fd7e05077256605885c82ffd8221bc94 (diff) | |
merge revision(s) b176315827d1082f43628013a7d89fda02724d33: [Backport #20324] (#10329)
[Bug #20324] Uncomparable ranges are not overlapping
| -rw-r--r-- | range.c | 12 | ||||
| -rw-r--r-- | test/ruby/test_range.rb | 2 | ||||
| -rw-r--r-- | version.h | 2 |
3 files changed, 13 insertions, 3 deletions
@@ -2373,8 +2373,16 @@ range_overlap(VALUE range, VALUE other) if (empty_region_p(self_beg, other_end, other_excl)) return Qfalse; if (empty_region_p(other_beg, self_end, self_excl)) return Qfalse; - /* if both begin values are equal, no more comparisons needed */ - if (rb_equal(self_beg, other_beg)) return Qtrue; + if (!NIL_P(self_beg) && !NIL_P(other_beg)) { + VALUE cmp = rb_funcall(self_beg, id_cmp, 1, other_beg); + if (NIL_P(cmp)) return Qfalse; + /* if both begin values are equal, no more comparisons needed */ + if (rb_cmpint(cmp, self_beg, other_beg) == 0) return Qtrue; + } + else if (NIL_P(self_beg) && NIL_P(other_beg)) { + VALUE cmp = rb_funcall(self_end, id_cmp, 1, other_end); + return RBOOL(!NIL_P(cmp)); + } if (empty_region_p(self_beg, self_end, self_excl)) return Qfalse; if (empty_region_p(other_beg, other_end, other_excl)) return Qfalse; diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index fe14bb9b3b..2aa69dc6a4 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -1265,6 +1265,8 @@ class TestRange < Test::Unit::TestCase assert_operator(0.., :overlap?, 1..) assert_not_operator((1..3), :overlap?, ('a'..'d')) + assert_not_operator((1..), :overlap?, ('a'..)) + assert_not_operator((..1), :overlap?, (..'a')) assert_raise(TypeError) { (0..).overlap?(1) } assert_raise(TypeError) { (0..).overlap?(nil) } @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 19 +#define RUBY_PATCHLEVEL 20 #include "ruby/version.h" #include "ruby/internal/abi.h" |
