summaryrefslogtreecommitdiff
path: root/pack.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-24 18:59:53 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-24 18:59:53 +0000
commit8916f020767bba506a696ad22cac8d541f45d33b (patch)
tree37ddb7b80f3c1dc90bb6e094f37de5a9566bece3 /pack.c
parentac60468656989736752d406d570767c490820fa3 (diff)
merge revision(s) 60059: [Backport #13949]
pack.c: unpack "M" may be ASCII only * pack.c (pack_unpack_internal): set ASCII only properly on "M", may be ASCII only. [ruby-core:83055] [Bug #13949] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@61454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
-rw-r--r--pack.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/pack.c b/pack.c
index d275a286b0..33bcb2b7d7 100644
--- a/pack.c
+++ b/pack.c
@@ -1609,6 +1609,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode)
{
VALUE buf = infected_str_new(0, send - s, str);
char *ptr = RSTRING_PTR(buf), *ss = s;
+ int csum = 0;
int c1, c2;
while (s < send) {
@@ -1620,18 +1621,19 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode)
if ((c1 = hex2num(*s)) == -1) break;
if (++s == send) break;
if ((c2 = hex2num(*s)) == -1) break;
- *ptr++ = castchar(c1 << 4 | c2);
+ csum |= *ptr++ = castchar(c1 << 4 | c2);
}
}
else {
- *ptr++ = *s;
+ csum |= *ptr++ = *s;
}
s++;
ss = s;
}
rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
rb_str_buf_cat(buf, ss, send-ss);
- ENCODING_CODERANGE_SET(buf, rb_ascii8bit_encindex(), ENC_CODERANGE_VALID);
+ csum = ISASCII(csum) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
+ ENCODING_CODERANGE_SET(buf, rb_ascii8bit_encindex(), csum);
UNPACK_PUSH(buf);
}
break;