summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--marshal.c1
-rw-r--r--test/ruby/test_marshal.rb6
2 files changed, 6 insertions, 1 deletions
diff --git a/marshal.c b/marshal.c
index 47b13bc684..ab0e63c701 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1422,6 +1422,7 @@ ruby2_keywords_flag_check(VALUE sym)
{
const char *p;
long l;
+ if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return 0;
RSTRING_GETMEM(sym, p, l);
if (l <= 0) return 0;
if (name_equal(name_s_ruby2_keywords_flag, rb_strlen_lit(name_s_ruby2_keywords_flag), p, l)) {
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index 619aaa6736..9eea3c272e 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -810,7 +810,11 @@ class TestMarshal < Test::Unit::TestCase
hash = Marshal.load(data)
assert_equal(42, ruby2_keywords_test(*[hash]))
- hash2 = Marshal.load(data.sub!(/\x06K(?=T\z)/, "\x08KEY"))
+ hash2 = Marshal.load(data.sub(/\x06K(?=T\z)/, "\x08KEY"))
+ assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
+ ruby2_keywords_test(*[hash2])
+ }
+ hash2 = Marshal.load(data.sub(/:\x06K(?=T\z)/, "I\\&\x06:\x0dencoding\"\x0dUTF-16LE"))
assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
ruby2_keywords_test(*[hash2])
}