From 40bc846bf8a0504777c9f5bc4223faa8888889a6 Mon Sep 17 00:00:00 2001 From: stomar Date: Sun, 21 May 2017 19:28:48 +0000 Subject: string.c: fix String#{casecmp,casecmp?} for non-string arguments * string.c: make String#{casecmp,casecmp?} return nil for non-string arguments instead of raising a TypeError. * test/ruby/test_string.rb: add tests. Reported by Marcus Stollsteimer. Based on a patch by Shingo Morita. [ruby-core:80145] [Bug #13312] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_string.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ruby/test_string.rb') diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index e1b27fc2be..232d92b2a3 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2321,6 +2321,13 @@ CODE assert_equal(1, "FoO".casecmp("BaR")) assert_equal(-1, "baR".casecmp("FoO")) assert_equal(1, "\u3042B".casecmp("\u3042a")) + + assert_nil("foo".casecmp(:foo)) + assert_nil("foo".casecmp(Object.new)) + + o = Object.new + def o.to_str; "fOO"; end + assert_equal(0, "FoO".casecmp(o)) end def test_casecmp? @@ -2328,6 +2335,13 @@ CODE assert_equal(false, 'FoO'.casecmp?('BaR')) assert_equal(false, 'baR'.casecmp?('FoO')) assert_equal(true, 'äöü'.casecmp?('ÄÖÜ')) + + assert_nil("foo".casecmp?(:foo)) + assert_nil("foo".casecmp?(Object.new)) + + o = Object.new + def o.to_str; "fOO"; end + assert_equal(true, "FoO".casecmp?(o)) end def test_upcase2 -- cgit v1.2.3