summaryrefslogtreecommitdiffstats
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
commit9a76c3e9a7bc78af3cf9133a08f57d77e95131f7 (patch)
treeee67a4e05e1384569235df1f434a1040d606efd5 /string.c
parent6c14cccf7dca02821daed90c9457ee67ffec429f (diff)
downloadruby-9a76c3e9a7bc78af3cf9133a08f57d77e95131f7.tar.gz
ruby-9a76c3e9a7bc78af3cf9133a08f57d77e95131f7.tar.xz
ruby-9a76c3e9a7bc78af3cf9133a08f57d77e95131f7.zip
* string.c (rb_str_new_frozen): must not change encoding of frozen
shared string. [ruby-dev:39068] git-svn-id: http://svn.ruby-lang.org/repos/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 06edf3b8d..39df54b19 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));