https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-03-13T20:49:48ZRuby Issue Tracking SystemRuby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=635722017-03-13T20:49:48Zstomar (Marcus Stollsteimer)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/63572/diff?detail_id=44289">diff</a>)</li></ul> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=639722017-03-29T10:11:31Zshingo (shingo morita)
<ul><li><strong>File</strong> <a href="/attachments/6464">patch.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/6464/patch.diff">patch.diff</a> added</li></ul><p>I agree this is not expecting behavior. then I made a patch for this.<br>
Added test codes below.</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 7dbf27e..3b72d25 100644
</span><span class="gd">--- a/test/ruby/test_string.rb
</span><span class="gi">+++ b/test/ruby/test_string.rb
</span><span class="p">@@ -2318,6 +2318,12 @@</span> def test_compare_different_encoding_string
def test_casecmp
assert_equal(1, "\u3042B".casecmp("\u3042a"))
<span class="gi">+ assert_nil("Foo".casecmp(:Foo))
+ assert_nil("1".casecmp(1))
+
+ o = Object.new
+ def o.to_str; "abcde"; end
+ assert_equal(1, "abcdef".casecmp(o))
</span> end
def test_casecmp?
<span class="p">@@ -2325,6 +2331,12 @@</span> def test_casecmp?
assert_equal(false, 'FoO'.casecmp?('BaR'))
assert_equal(false, 'baR'.casecmp?('FoO'))
assert_equal(true, 'äöü'.casecmp?('ÄÖÜ'))
<span class="gi">+ assert_nil("Foo".casecmp?(:Foo))
+ assert_nil("1".casecmp?(1))
+
+ o = Object.new
+ def o.to_str; "foo"; end
+ assert_equal(true, "Foo".casecmp?(o))
</span> end
def test_upcase2
</code></pre> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=649192017-05-19T07:24:53Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>stomar (Marcus Stollsteimer)</i></li></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/5507">@stomar (Marcus Stollsteimer)</a></p>
<p>It should return nil same as other comparison methods. Can you handle this?</p> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=649852017-05-20T14:07:35Zstomar (Marcus Stollsteimer)
<ul></ul><blockquote>
<p>Can you handle this?</p>
</blockquote>
<p>Ok.</p> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=650082017-05-21T19:28:54Zstomar (Marcus Stollsteimer)
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r58837.</p>
<hr>
<p>string.c: fix String#{casecmp,casecmp?} for non-string arguments</p>
<ul>
<li>
<p>string.c: make String#{casecmp,casecmp?} return nil for<br>
non-string arguments instead of raising a TypeError.</p>
</li>
<li>
<p>test/ruby/test_string.rb: add tests.</p>
</li>
</ul>
<p>Reported by Marcus Stollsteimer. Based on a patch by Shingo Morita.<br>
<a href="/issues/13312">[ruby-core:80145]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: String#casecmp raises TypeError instead of returning nil (Closed)" href="https://bugs.ruby-lang.org/issues/13312">#13312</a>]</p> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=650092017-05-21T20:05:11Zstomar (Marcus Stollsteimer)
<ul></ul><p>I did not include the type check in <code>str_casecmp</code>, which seems superfluous to me. I also adjusted the tests, docs, and examples to those of the corresponding Symbol methods, and fixed the code formatting.</p>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/572">@hsbt (Hiroshi SHIBATA)</a></p>
<p>I also added a NEWS entry and updated the specs with a version guard for 2.5 (I do not know how this would be handled in case the change should be backported).</p> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=650832017-05-25T09:04:03ZEregon (Benoit Daloze)
<ul></ul><p>stomar (Marcus Stollsteimer) wrote:</p>
<blockquote>
<p>I also added a NEWS entry and updated the specs with a version guard for 2.5 (I do not know how this would be handled in case the change should be backported).</p>
</blockquote>
<p>Thanks, r58839 looks great.</p>
<p>In case of backport we can adjust the version guard, but only after a release of 2.x as we need to test against releases in ruby/spec Travis and locally.</p> Ruby master - Bug #13312: String#casecmp raises TypeError instead of returning nilhttps://bugs.ruby-lang.org/issues/13312?journal_id=655382017-06-29T16:54:38Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Backport</strong> changed from <i>2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN</i> to <i>2.2: WONTFIX, 2.3: WONTFIX, 2.4: UNKNOWN</i></li></ul><p>I think this change may not cause any compatibility issue with real-world scripts, but it means that nobody hits this problem, too.<br>
Then I decided not to backport to ruby_2_3.</p>