Project

General

Profile

Bug #7050 ยป 0001-set-encoding-to-ASCII-for-appropriate-String-unpack-.patch

Eregon (Benoit Daloze), 09/23/2012 05:03 AM

View differences:

pack.c
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;
......
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;
......
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)
......
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)
test/ruby/test_pack.rb
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
......
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
    (1-1/1)