summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--pack.c8
-rw-r--r--test/ruby/test_pack.rb6
-rw-r--r--test/test_securerandom.rb4
4 files changed, 25 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 32696cf9ed..9e34487b65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Fri Oct 19 22:11:55 2012 Benoit Daloze <eregontp@gmail.com>
+
+ * pack.c (pack_unpack): set encoding of the
+ 'H','h','B' and 'B' modifiers to US-ASCII.
+
+ * test/ruby/test_pack.rb: tests for the above.
+ [ruby-core:47653][Bug #7050]
+
+ * test/test_securerandom.rb: tests for SecureRandom.hex
+ from tenderlove. [ruby-core:46792][Bug #6799]
+
Fri Oct 19 19:29:11 2012 Koichi Sasada <ko1@atdot.net>
* method.h (rb_method_cfunc_t::invoker): add new field (func ptr)
diff --git a/pack.c b/pack.c
index 06086ba2af..fabbb7ddb0 100644
--- a/pack.c
+++ b/pack.c
@@ -1459,7 +1459,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
+ UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
t = RSTRING_PTR(bitstr);
for (i=0; i<len; i++) {
if (i & 7) bits >>= 1;
@@ -1479,7 +1479,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
+ UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
t = RSTRING_PTR(bitstr);
for (i=0; i<len; i++) {
if (i & 7) bits <<= 1;
@@ -1499,7 +1499,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
+ UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
t = RSTRING_PTR(bitstr);
for (i=0; i<len; i++) {
if (i & 1)
@@ -1521,7 +1521,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- UNPACK_PUSH(bitstr = rb_str_new(0, len));
+ UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
t = RSTRING_PTR(bitstr);
for (i=0; i<len; i++) {
if (i & 1)
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index 5a19cb3d56..1463bd035b 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -280,6 +280,9 @@ class TestPack < Test::Unit::TestCase
assert_equal(["1"], "\x80".unpack("B1"))
assert_equal(["10"], "\x80".unpack("B2"))
assert_equal(["100"], "\x80".unpack("B3"))
+
+ assert_equal(Encoding::US_ASCII, "\xff\x00".unpack("b*")[0].encoding)
+ assert_equal(Encoding::US_ASCII, "\xff\x00".unpack("B*")[0].encoding)
end
def test_pack_unpack_hH
@@ -320,6 +323,9 @@ class TestPack < Test::Unit::TestCase
assert_equal(["10e"], "\x10\xef".unpack("H3"))
assert_equal(["10ef"], "\x10\xef".unpack("H4"))
assert_equal(["10ef"], "\x10\xef".unpack("H5"))
+
+ assert_equal(Encoding::US_ASCII, "\x10\xef".unpack("h*")[0].encoding)
+ assert_equal(Encoding::US_ASCII, "\x10\xef".unpack("H*")[0].encoding)
end
def test_pack_unpack_cC
diff --git a/test/test_securerandom.rb b/test/test_securerandom.rb
index f3e1bf0afc..f3c9a1af92 100644
--- a/test/test_securerandom.rb
+++ b/test/test_securerandom.rb
@@ -111,6 +111,10 @@ end
end
end
+ def test_hex_encoding
+ assert_equal(Encoding::US_ASCII, @it.hex.encoding)
+ end
+
def test_s_base64
assert_equal(16, @it.base64.unpack('m*')[0].size)
17.times do |idx|