1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* transcode.c (str_encode_bang, encoded_dup): if nothing was

transcoded, just set encoding but leave coderange unchanged as
  forcee_encoding.  [ruby-core:43557][Bug #6190]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-22 14:14:39 +00:00
parent 7cbff3b9dd
commit 2b84626193
3 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Thu Mar 22 23:14:36 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* transcode.c (str_encode_bang, encoded_dup): if nothing was
transcoded, just set encoding but leave coderange unchanged as
forcee_encoding. [ruby-core:43557][Bug #6190]
Thu Mar 22 22:30:44 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
* io.c (static int io_fflush): add the definition.

View file

@ -1410,6 +1410,14 @@ class TestM17N < Test::Unit::TestCase
assert_equal(true, s.valid_encoding?)
s << "\xff".force_encoding("utf-16be")
assert_equal(false, s.valid_encoding?, bug4018)
bug6190 = '[ruby-core:43557]'
s = "\xe9"
s = s.encode("utf-8", "utf-8")
assert_equal(false, s.valid_encoding?, bug6190)
s = "\xe9"
s.encode!("utf-8", "utf-8")
assert_equal(false, s.valid_encoding?, bug6190)
end
def test_getbyte

View file

@ -2785,6 +2785,10 @@ str_encode_bang(int argc, VALUE *argv, VALUE str)
encidx = str_transcode(argc, argv, &newstr);
if (encidx < 0) return str;
if (newstr == str) {
rb_enc_associate_index(str, encidx);
return str;
}
rb_str_shared_replace(str, newstr);
return str_encode_associate(str, encidx);
}
@ -2871,6 +2875,8 @@ encoded_dup(VALUE newstr, VALUE str, int encidx)
if (encidx < 0) return rb_str_dup(str);
if (newstr == str) {
newstr = rb_str_dup(str);
rb_enc_associate_index(newstr, encidx);
return newstr;
}
else {
RBASIC(newstr)->klass = rb_obj_class(str);