Set correct termlen for frozen strings
Frozen strings should have the same termlen as the original string when copy_encoding is true.
This commit is contained in:
parent
44368b5f8b
commit
5f55b03716
Notes:
git
2022-01-07 04:33:59 +09:00
5
string.c
5
string.c
@ -1419,9 +1419,10 @@ str_new_frozen_buffer(VALUE klass, VALUE orig, int copy_encoding)
|
|||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
long len = RSTRING_LEN(orig);
|
long len = RSTRING_LEN(orig);
|
||||||
|
int termlen = copy_encoding ? TERM_LEN(orig) : 1;
|
||||||
|
|
||||||
if (STR_EMBED_P(orig) || STR_EMBEDDABLE_P(len, 1)) {
|
if (STR_EMBED_P(orig) || STR_EMBEDDABLE_P(len, termlen)) {
|
||||||
str = str_new(klass, RSTRING_PTR(orig), len);
|
str = str_new0(klass, RSTRING_PTR(orig), len, termlen);
|
||||||
assert(STR_EMBED_P(str));
|
assert(STR_EMBED_P(str));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user