ruby-changes:24537
From: eregon <ko1@a...>
Date: Wed, 1 Aug 2012 22:31:03 +0900 (JST)
Subject: [ruby-changes:24537] eregon:r36588 (trunk): ext/digest/digest.c (hexencode_str_new): return an ASCII string
eregon 2012-08-01 22:30:51 +0900 (Wed, 01 Aug 2012) New Revision: 36588 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36588 Log: ext/digest/digest.c (hexencode_str_new): return an ASCII string * test/digest: tests for all kind of digests encodings [ruby-core:46792][Bug #6799] Modified files: trunk/ChangeLog trunk/ext/digest/digest.c trunk/test/digest/test_digest.rb trunk/test/digest/test_digest_extend.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36587) +++ ChangeLog (revision 36588) @@ -1,3 +1,10 @@ +Wed Aug 1 22:29:12 2012 Benoit Daloze <eregontp@g...> + + ext/digest/digest.c (hexencode_str_new): return an ASCII string + + * test/digest: tests for all kind of digests encodings + [ruby-core:46792][Bug #6799] + Wed Aug 1 05:50:53 2012 Hiroshi Shirosaki <h.shirosaki@g...> * test/ruby/test_rubyoptions.rb (TestRubyOptions#test_encoding): Index: ext/digest/digest.c =================================================================== --- ext/digest/digest.c (revision 36587) +++ ext/digest/digest.c (revision 36588) @@ -99,7 +99,7 @@ rb_raise(rb_eRuntimeError, "digest string too long"); } - str = rb_str_new(0, digest_len * 2); + str = rb_usascii_str_new(0, digest_len * 2); for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) { unsigned char byte = digest[i]; Index: test/digest/test_digest.rb =================================================================== --- test/digest/test_digest.rb (revision 36587) +++ test/digest/test_digest.rb (revision 36588) @@ -25,21 +25,27 @@ def test_s_hexdigest self.class::DATA.each do |str, hexdigest| - assert_equal(hexdigest, self.class::ALGO.hexdigest(str)) + actual = self.class::ALGO.hexdigest(str) + assert_equal(hexdigest, actual) + assert_equal(Encoding::US_ASCII, actual.encoding) end end def test_s_base64digest self.class::DATA.each do |str, hexdigest| digest = [hexdigest].pack("H*") - assert_equal([digest].pack("m0"), self.class::ALGO.base64digest(str)) + actual = self.class::ALGO.base64digest(str) + assert_equal([digest].pack("m0"), actual) + assert_equal(Encoding::US_ASCII, actual.encoding) end end def test_s_digest self.class::DATA.each do |str, hexdigest| digest = [hexdigest].pack("H*") - assert_equal(digest, self.class::ALGO.digest(str)) + actual = self.class::ALGO.digest(str) + assert_equal(digest, actual) + assert_equal(Encoding::BINARY, actual.encoding) end end Index: test/digest/test_digest_extend.rb =================================================================== --- test/digest/test_digest_extend.rb (revision 36587) +++ test/digest/test_digest_extend.rb (revision 36588) @@ -49,6 +49,7 @@ (0..0xff).to_a.map { |c| sprintf("%02x", c ) }.join(''), Digest.hexencode((0..0xff).to_a.map { |c| c.chr }.join('')) ) + assert_equal(Encoding::US_ASCII, Digest.hexencode("\1\2").encoding) end def test_class_reset -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/