summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-31 13:28:39 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-31 13:28:39 +0000
commit4e2989ee8f53d421e9fef21df67420629285b357 (patch)
tree7b1cf6408dcbf91f7588afa9fab02c04f5a25383
parenta852edd817da6d66b9e034e18f68b5b75566a9b2 (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_3@62138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--pack.c8
-rw-r--r--test/ruby/test_pack.rb5
-rw-r--r--version.h2
4 files changed, 18 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index aa96075e1e..c68abfdc69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Jan 31 22:28:20 2018 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ 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]
+
Wed Jan 31 22:26:13 2018 Nobuyoshi Nakada <nobu@ruby-lang.org>
string.c: ASCII-incompatible is not ASCII only
diff --git a/pack.c b/pack.c
index d19f9d1dd2..e27eeef6cc 100644
--- a/pack.c
+++ b/pack.c
@@ -1706,6 +1706,7 @@ pack_unpack(VALUE str, VALUE fmt)
{
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) {
@@ -1717,18 +1718,19 @@ pack_unpack(VALUE str, VALUE fmt)
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;
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index b0046b2a27..b0fd0b7158 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -686,6 +686,11 @@ EXPECTED
assert_equal(["pre=hoge"], "pre=hoge".unpack("M"))
assert_equal(["pre==31after"], "pre==31after".unpack("M"))
assert_equal(["pre===31after"], "pre===31after".unpack("M"))
+
+ bug = '[ruby-core:83055] [Bug #13949]'
+ s = "abcdef".unpack("M").first
+ assert_equal(Encoding::ASCII_8BIT, s.encoding)
+ assert_predicate(s, :ascii_only?, bug)
end
def test_pack_unpack_P2
diff --git a/version.h b/version.h
index 9ab30a1100..f65d90b6e3 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.7"
#define RUBY_RELEASE_DATE "2018-01-31"
-#define RUBY_PATCHLEVEL 399
+#define RUBY_PATCHLEVEL 400
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 1