ruby-changes:34287
From: eregon <ko1@a...>
Date: Sat, 7 Jun 2014 06:06:01 +0900 (JST)
Subject: [ruby-changes:34287] eregon:r46368 (trunk): digest.c: fix #== for non-string arguments
eregon 2014-06-07 06:05:48 +0900 (Sat, 07 Jun 2014) New Revision: 46368 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46368 Log: digest.c: fix #== for non-string arguments * ext/digest/digest.c (rb_digest_instance_equal): fix #== for non-string arguments. [ruby-core:62967] [Bug #9913] * test/digest/test_digest.rb: add test for above. Modified files: trunk/ChangeLog trunk/ext/digest/digest.c trunk/test/digest/test_digest.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46367) +++ ChangeLog (revision 46368) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 7 06:03:11 2014 Benoit Daloze <eregontp@g...> + + * ext/digest/digest.c (rb_digest_instance_equal): + fix #== for non-string arguments. [ruby-core:62967] [Bug #9913] + + * test/digest/test_digest.rb: add test for above. + Fri Jun 6 22:19:26 2014 Nobuyoshi Nakada <nobu@r...> * compile.c (private_recv_p): check by node type, instead of a Index: ext/digest/digest.c =================================================================== --- ext/digest/digest.c (revision 46367) +++ ext/digest/digest.c (revision 46368) @@ -370,9 +370,11 @@ rb_digest_instance_equal(VALUE self, VAL https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c#L370 if (rb_obj_is_kind_of(other, rb_mDigest_Instance) == Qtrue) { str1 = rb_digest_instance_digest(0, 0, self); str2 = rb_digest_instance_digest(0, 0, other); - } else { + } else if (!NIL_P(rb_check_string_type(other))) { str1 = rb_digest_instance_to_s(self); str2 = other; + } else { + return Qfalse; } /* never blindly assume that subclass methods return strings */ Index: test/digest/test_digest.rb =================================================================== --- test/digest/test_digest.rb (revision 46367) +++ test/digest/test_digest.rb (revision 46368) @@ -69,6 +69,9 @@ module TestDigest https://github.com/ruby/ruby/blob/trunk/test/digest/test_digest.rb#L69 assert_equal(md1, md1.clone, self.class::ALGO) + bug9913 = '[ruby-core:62967] [Bug #9913]' + assert_not_equal(md1, nil, bug9913) + md2 = self.class::ALGO.new md2 << "A" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/