mirror of
https://github.com/ruby/ruby.git
synced 2025-09-22 03:53:58 +02:00
pack.c: avoid returning uninitialized String
Fix unpacking with 'b', 'B', 'h' and 'H' format. Do not return an uninitialized String to Ruby before filling the content bytes. Fixes r11175 ("pack.c (pack_unpack): execute block if given with unpacked value instead of creating an array", 2006-10-15). [ruby-core:78841] [Bug #13075] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
256d8c9ecf
commit
b65b41861f
2 changed files with 16 additions and 4 deletions
|
@ -838,10 +838,18 @@ EXPECTED
|
|||
assert_equal addr, [buf].pack('p')
|
||||
end
|
||||
|
||||
def test_unpack_with_block
|
||||
ret = []; "ABCD".unpack("CCCC") {|v| ret << v }
|
||||
assert_equal [65, 66, 67, 68], ret
|
||||
ret = []; "A".unpack("B*") {|v| ret << v }
|
||||
assert_equal ["01000001"], ret
|
||||
end
|
||||
|
||||
def test_unpack1
|
||||
assert_equal 65, "A".unpack1("C")
|
||||
assert_equal 68, "ABCD".unpack1("x3C")
|
||||
assert_equal 0x3042, "\u{3042 3044 3046}".unpack1("U*")
|
||||
assert_equal "hogefuga", "aG9nZWZ1Z2E=".unpack1("m")
|
||||
assert_equal "01000001", "A".unpack1("B*")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue