Fix str.replace when replacement string contains nil bytes

This commit is contained in:
K. Lange 2022-03-24 10:23:52 +09:00
parent e24ea3d32c
commit 799952c298

View File

@ -573,8 +573,8 @@ KRK_METHOD(str,replace,{
char * c = self->chars;
while (i < self->length) {
if ( substringMatch(c, self->length - i, oldStr->chars, oldStr->length) && (IS_NONE(count) || replacements < AS_INTEGER(count))) {
for (char * o = newStr->chars; *o; o++ ){
PUSH_CHAR(*o);
for (size_t j = 0; j < newStr->length; j++) {
PUSH_CHAR(newStr->chars[j]);
}
if (oldStr->length == 0) {
PUSH_CHAR(*c);