summaryrefslogtreecommitdiff
path: root/transcode.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-22 14:14:39 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-22 14:14:39 (GMT)
commit2b84626193c43ba49f2f4663aad76810684bd45c (patch)
treeddef68ab54e37b71ec7e410ea2ea0cb94fa7509f /transcode.c
parent7cbff3b9dd51dbb43cbd3757bd719b52eb03a3b1 (diff)
* 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
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/transcode.c b/transcode.c
index c0049fd..1378402 100644
--- a/transcode.c
+++ b/transcode.c
@@ -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);