string.c: consider widechar
* string.c (str_make_independent_expand): consider wide char encoding. [Fix GH-821] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
622f3f14b6
commit
34d4105556
4
string.c
4
string.c
@ -1589,11 +1589,11 @@ str_make_independent_expand(VALUE str, long expand)
|
||||
|
||||
if (len > capa) len = capa;
|
||||
|
||||
if (capa <= RSTRING_EMBED_LEN_MAX && !STR_EMBED_P(str)) {
|
||||
if (capa + termlen - 1 <= RSTRING_EMBED_LEN_MAX && !STR_EMBED_P(str)) {
|
||||
ptr = RSTRING(str)->as.heap.ptr;
|
||||
STR_SET_EMBED(str);
|
||||
memcpy(RSTRING(str)->as.ary, ptr, len);
|
||||
RSTRING(str)->as.ary[len] = '\0'; /* Ensure string is terminated */
|
||||
TERM_FILL(RSTRING(str)->as.ary + len, termlen);
|
||||
STR_SET_EMBED_LEN(str, len);
|
||||
return;
|
||||
}
|
||||
|
@ -93,6 +93,17 @@ class Test_StringCStr < Test::Unit::TestCase
|
||||
{}[string] = 1
|
||||
non_terminated = "#{string}#{nil}"
|
||||
assert_nil(Bug::String.cstr_term_char(non_terminated), gh821)
|
||||
|
||||
result = {}
|
||||
WCHARS.map do |enc|
|
||||
embedded_string = "ab".encode(enc)
|
||||
string = embedded_string.gsub("b".encode(enc), "1".encode(enc))
|
||||
{}[string] = 1
|
||||
non_terminated = "#{string}#{nil}"
|
||||
c = Bug::String.cstr_term_char(non_terminated)
|
||||
result[enc] = c if c
|
||||
end
|
||||
assert_empty(result, gh821)
|
||||
end
|
||||
|
||||
def assert_wchars_term_char(str)
|
||||
|
Loading…
x
Reference in New Issue
Block a user