diff options
| author | nagachika <nagachika@ruby-lang.org> | 2023-09-24 13:48:08 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2023-09-24 13:48:08 +0900 |
| commit | 217ef2bf89b3861e83c2e2a3a633c019f0731de6 (patch) | |
| tree | 25742ba8b2dd1b8e15371bc9aae8a0ef6bd54f59 | |
| parent | a7335e11e354d1ee2e15233f32f087230069ad5c (diff) | |
merge revision(s) 25711683e86271385e8abe09a9c03782000e48db: [Backport #19864]
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]
---
range.c | 9 +++++++++
test/ruby/test_range.rb | 23 +++++++++++++++++++++++
2 files changed, 32 insertions(+)
| -rw-r--r-- | range.c | 9 | ||||
| -rw-r--r-- | test/ruby/test_range.rb | 23 | ||||
| -rw-r--r-- | version.h | 2 |
3 files changed, 33 insertions, 1 deletions
@@ -1817,6 +1817,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)) { @@ -1825,12 +1826,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); } diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 54365f1277..d84184c3bf 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -3,6 +3,7 @@ require 'test/unit' require 'delegate' require 'timeout' require 'bigdecimal' +require 'date' require 'rbconfig/sizeof' class TestRange < Test::Unit::TestCase @@ -585,6 +586,28 @@ class TestRange < Test::Unit::TestCase assert_operator(c.new(0)..c.new(10), :===, c.new(5), bug12003) end + def test_eqq_unbounded_ruby_bug_19864 + t1 = Date.today + t2 = t1 + 1 + assert_equal(true, (..t1) === t1) + assert_equal(false, (..t1) === t2) + assert_equal(true, (..t2) === t1) + assert_equal(true, (..t2) === t2) + assert_equal(false, (...t1) === t1) + assert_equal(false, (...t1) === t2) + assert_equal(true, (...t2) === t1) + assert_equal(false, (...t2) === t2) + + assert_equal(true, (t1..) === t1) + assert_equal(true, (t1..) === t2) + assert_equal(false, (t2..) === t1) + assert_equal(true, (t2..) === t2) + assert_equal(true, (t1...) === t1) + assert_equal(true, (t1...) === t2) + assert_equal(false, (t2...) === t1) + assert_equal(true, (t2...) === t2) + end + def test_eqq_non_iteratable k = Class.new do include Comparable @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 2 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 115 +#define RUBY_PATCHLEVEL 116 #include "ruby/version.h" #include "ruby/internal/abi.h" |
