mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[ruby/json] Always dup argument to preserve original encoding for force_encoding
db9a489ca2
This commit is contained in:
parent
57e1b64c81
commit
20dc1e5c25
2 changed files with 7 additions and 4 deletions
|
@ -673,10 +673,7 @@ static VALUE convert_encoding(VALUE source)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encindex == binary_encindex) {
|
if (encindex == binary_encindex) {
|
||||||
if (OBJ_FROZEN(source)) {
|
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
|
||||||
source = rb_str_dup(source);
|
|
||||||
}
|
|
||||||
return rb_enc_associate_index(source, utf8_encindex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rb_str_conv_enc(source, rb_enc_from_index(encindex), rb_utf8_encoding());
|
return rb_str_conv_enc(source, rb_enc_from_index(encindex), rb_utf8_encoding());
|
||||||
|
|
|
@ -26,6 +26,12 @@ class JSONParserTest < Test::Unit::TestCase
|
||||||
assert_equal Encoding::UTF_16, source.encoding
|
assert_equal Encoding::UTF_16, source.encoding
|
||||||
end if defined?(Encoding::UTF_16)
|
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
|
def test_error_message_encoding
|
||||||
pend if RUBY_ENGINE == 'truffleruby'
|
pend if RUBY_ENGINE == 'truffleruby'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue