diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-16 11:39:21 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-16 11:39:21 +0000 |
commit | b76d7afffc5f455bbe1b3fac95ed8f2c4a26fe42 (patch) | |
tree | 0a244ca3c43c9edd11d37c6a4278f5f43cdbf1c8 | |
parent | ef62988ecce58edc1ffbd6aa70ffd328a03b0923 (diff) |
merge revision(s) 55181: [Backport #12431]
* transcode.c (str_transcode0): scrub in the given encoding when
the source encoding is given, not in the encoding of the
receiver. [ruby-core:75732] [Bug #12431]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | string.c | 8 | ||||
-rw-r--r-- | test/ruby/test_transcode.rb | 3 | ||||
-rw-r--r-- | transcode.c | 2 | ||||
-rw-r--r-- | version.h | 2 |
6 files changed, 18 insertions, 4 deletions
@@ -1,3 +1,9 @@ +Tue Aug 16 20:34:22 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * transcode.c (str_transcode0): scrub in the given encoding when + the source encoding is given, not in the encoding of the + receiver. [ruby-core:75732] [Bug #12431] + Tue Aug 16 20:30:53 2016 Kazuki Yamaguchi <k@rhe.jp> * ext/openssl/ossl_pkey_dh.c (ossl_dh_compute_key): Check that the DH diff --git a/internal.h b/internal.h index ee55db3cb4..7a76ba2548 100644 --- a/internal.h +++ b/internal.h @@ -990,6 +990,7 @@ void rb_str_fill_terminator(VALUE str, const int termlen); VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg); #ifdef RUBY_ENCODING_H VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc); +VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl); #endif #define STR_NOEMBED FL_USER1 #define STR_SHARED FL_USER2 /* = ELTS_SHARED */ @@ -8255,8 +8255,13 @@ str_compat_and_valid(VALUE str, rb_encoding *enc) VALUE rb_str_scrub(VALUE str, VALUE repl) { + return rb_enc_str_scrub(STR_ENC_GET(str), str, repl); +} + +VALUE +rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl) +{ int cr = ENC_CODERANGE(str); - rb_encoding *enc; int encidx; VALUE buf = Qnil; const char *rep; @@ -8266,7 +8271,6 @@ rb_str_scrub(VALUE str, VALUE repl) if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID) return Qnil; - enc = STR_ENC_GET(str); if (!NIL_P(repl)) { repl = str_compat_and_valid(repl, enc); tainted = OBJ_TAINTED_RAW(repl); diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 4bade11a51..fbc196925f 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -1212,6 +1212,9 @@ class TestTranscode < Test::Unit::TestCase def test_invalid_replace_string assert_equal("a<x>A", "a\x80A".encode("us-ascii", "euc-jp", :invalid=>:replace, :replace=>"<x>")) assert_equal("a<x>A", "a\x80A".encode("us-ascii", "euc-jis-2004", :invalid=>:replace, :replace=>"<x>")) + s = "abcd\u{c1}" + r = s.b.encode("UTF-8", "UTF-8", invalid: :replace, replace: "\u{fffd}") + assert_equal(s, r) end def test_undef_replace diff --git a/transcode.c b/transcode.c index 37934b5092..f474d903cb 100644 --- a/transcode.c +++ b/transcode.c @@ -2700,7 +2700,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts) if (!NIL_P(ecopts)) { rep = rb_hash_aref(ecopts, sym_replace); } - dest = rb_str_scrub(str, rep); + dest = rb_enc_str_scrub(senc, str, rep); if (NIL_P(dest)) dest = str; *self = dest; return dencidx; @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.6" #define RUBY_RELEASE_DATE "2016-08-16" -#define RUBY_PATCHLEVEL 362 +#define RUBY_PATCHLEVEL 363 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 8 |