Permalink
Browse files

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent f52eefe commit 61b624d149204c2b1c17a2852d088b2eb2aa010b @eregon eregon committed Aug 1, 2012
Showing with 18 additions and 4 deletions.
  1. +7 −0 ChangeLog
  2. +1 −1 ext/digest/digest.c
  3. +9 −3 test/digest/test_digest.rb
  4. +1 −0 test/digest/test_digest_extend.rb
View
@@ -1,3 +1,10 @@
+Wed Aug 1 22:29:12 2012 Benoit Daloze <eregontp@gmail.com>
+
+ 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@gmail.com>
* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_encoding):
View
@@ -99,7 +99,7 @@ hexencode_str_new(VALUE str_digest)
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];
View
@@ -25,21 +25,27 @@ def test_s_new
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
@@ -49,6 +49,7 @@ def test_digest_s_hexencode
(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

0 comments on commit 61b624d

Please sign in to comment.