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

* 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
This commit is contained in:
nobu 2009-08-12 04:00:03 +00:00
parent df9f513387
commit 265bd9e661
3 changed files with 22 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Wed Aug 12 12:59:51 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_new_frozen): must not change encoding of frozen
shared string. [ruby-dev:39068]
Wed Aug 12 11:51:51 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (rb_cv_broken_crypt): needs more checks.

View file

@ -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));

View file

@ -1791,4 +1791,17 @@ class TestString < Test::Unit::TestCase
("aaaaaaaa".."zzzzzzzz").each {|s| s.to_sym }
INPUT
end
def test_shared_force_encoding
s = "\u{3066}\u{3059}\u{3068}".gsub(//, '')
h = {}
h[s] = nil
k = h.keys[0]
assert_equal(s, k, '[ruby-dev:39068]')
assert_equal(Encoding::UTF_8, k.encoding, '[ruby-dev:39068]')
s.dup.force_encoding(Encoding::ASCII_8BIT).gsub(//, '')
k = h.keys[0]
assert_equal(s, k, '[ruby-dev:39068]')
assert_equal(Encoding::UTF_8, k.encoding, '[ruby-dev:39068]')
end
end