summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-12 04:00:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-12 04:00:03 +0000
commit265bd9e661061d364568f78b3c2649377bfe96b1 (patch)
treeee67a4e05e1384569235df1f434a1040d606efd5 /string.c
parentdf9f51338766ca090aaa2ed9818213eb7e2b8d8c (diff)
* string.c (rb_str_new_frozen): must not change encoding of frozen
shared string. [ruby-dev:39068] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/string.c b/string.c
index 06edf3b8d1..39df54b195 100644
--- a/string.c
+++ b/string.c
@@ -671,13 +671,14 @@ rb_str_new_frozen(VALUE orig)
assert(OBJ_FROZEN(str));
ofs = RSTRING_LEN(str) - RSTRING_LEN(orig);
if ((ofs > 0) || (klass != RBASIC(str)->klass) ||
- (!OBJ_TAINTED(str) && OBJ_TAINTED(orig))) {
+ (!OBJ_TAINTED(str) && OBJ_TAINTED(orig)) ||
+ ENCODING_GET(str) != ENCODING_GET(orig)) {
str = str_new3(klass, str);
RSTRING(str)->as.heap.ptr += ofs;
RSTRING(str)->as.heap.len -= ofs;
+ rb_enc_cr_str_exact_copy(str, orig);
+ OBJ_INFECT(str, orig);
}
- rb_enc_cr_str_exact_copy(str, orig);
- OBJ_INFECT(str, orig);
}
else if (STR_EMBED_P(orig)) {
str = str_new(klass, RSTRING_PTR(orig), RSTRING_LEN(orig));