diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_econv.rb | 1 | ||||
-rw-r--r-- | transcode.c | 5 |
3 files changed, 10 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Thu Dec 17 13:35:27 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * transcode.c (rb_econv_substr_append, econv_primitive_convert): + the result should be infected by the original string. + Thu Dec 17 09:46:08 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * re.c (reg_names_iter): should consider encoding of regexp. diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 8172bf99ef..6f098db454 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -680,6 +680,7 @@ class TestEncodingConverter < Test::Unit::TestCase ec = Encoding::Converter.new("utf-8", "euc-jp") assert_raise(Encoding::InvalidByteSequenceError) { ec.convert("a\x80") } assert_raise(Encoding::UndefinedConversionError) { ec.convert("\ufffd") } + assert_predicate(ec.convert("abc".taint), :tainted?) ret = ec.primitive_convert(nil, "", nil, nil) assert_equal(:finished, ret) assert_raise(ArgumentError) { ec.convert("a") } diff --git a/transcode.c b/transcode.c index 1977498bc6..c2032a897a 100644 --- a/transcode.c +++ b/transcode.c @@ -1854,6 +1854,7 @@ rb_econv_substr_append(rb_econv_t *ec, VALUE src, long off, long len, VALUE dst, src = rb_str_new_frozen(src); dst = rb_econv_append(ec, RSTRING_PTR(src) + off, len, dst, flags); RB_GC_GUARD(src); + OBJ_INFECT_RAW(dst, src); return dst; } @@ -3768,8 +3769,10 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self) res = rb_econv_convert(ec, &ip, is, &op, os, flags); rb_str_set_len(output, op-(unsigned char *)RSTRING_PTR(output)); - if (!NIL_P(input)) + if (!NIL_P(input)) { + OBJ_INFECT_RAW(output, input); rb_str_drop_bytes(input, ip - (unsigned char *)RSTRING_PTR(input)); + } if (NIL_P(output_bytesize_v) && res == econv_destination_buffer_full) { if (LONG_MAX / 2 < output_bytesize) |