summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/json/parser/parser.rl5
-rw-r--r--test/json/json_parser_test.rb6
2 files changed, 7 insertions, 4 deletions
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index e3b3f325e6..61674b7812 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -673,10 +673,7 @@ static VALUE convert_encoding(VALUE source)
}
if (encindex == binary_encindex) {
- if (OBJ_FROZEN(source)) {
- source = rb_str_dup(source);
- }
- return rb_enc_associate_index(source, utf8_encindex);
+ return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
}
return rb_str_conv_enc(source, rb_enc_from_index(encindex), rb_utf8_encoding());
diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb
index 610ea06f3f..d76281e6bc 100644
--- a/test/json/json_parser_test.rb
+++ b/test/json/json_parser_test.rb
@@ -26,6 +26,12 @@ class JSONParserTest < Test::Unit::TestCase
assert_equal Encoding::UTF_16, source.encoding
end if defined?(Encoding::UTF_16)
+ def test_argument_encoding_for_binary
+ source = "{}".encode("ASCII-8BIT")
+ JSON::Parser.new(source)
+ assert_equal Encoding::ASCII_8BIT, source.encoding
+ end if defined?(Encoding::ASCII_8BIT)
+
def test_error_message_encoding
pend if RUBY_ENGINE == 'truffleruby'