summaryrefslogtreecommitdiff
path: root/transcode.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-02 04:13:32 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-02 04:13:32 +0000
commitbe36df7f55a073e7fcb677497dfaf3c0bab12278 (patch)
tree2a5d4f95b73877fe4b36e53c119bf23095b1d662 /transcode.c
parentb6a72bcf2f868bf075d334d05c7522c426db080f (diff)
merge revision(s) 35112,35121: [Backport #6190]
* 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] * transcode.c (documentation for str_encode): Explain that transcoding to the same encoding is a no-op (i.e. no exceptions, no replacements,...). [ruby-core:43557][Bug #6190] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@40056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/transcode.c b/transcode.c
index 4c3a273e7a..045ce2e118 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2805,6 +2805,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);
}
@@ -2831,6 +2835,10 @@ static VALUE encoded_dup(VALUE newstr, VALUE str, int encidx);
* in the source encoding. The last form by default does not raise
* exceptions but uses replacement strings.
*
+ * Please note that conversion from an encoding +enc+ to the
+ * same encoding +enc+ is a no-op, i.e. the receiver is returned without
+ * any changes, and no exceptions are raised, even if there are invalid bytes.
+ *
* The +options+ Hash gives details for conversion and can have the following
* keys:
*
@@ -2891,6 +2899,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);