diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c index 455e87e0c..acd0b70c1 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.c @@ -1017,7 +1017,11 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se previous_start = current_position + 1; } - current_position++; + /* if not a continuation byte */ + if ((*replace_str_curr_p & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER) + { + current_position++; + } } if (ecma_is_value_empty (ret_value)) diff --git a/tests/jerry/string-prototype-replace.js b/tests/jerry/string-prototype-replace.js index c26fc2eae..985ccffed 100644 --- a/tests/jerry/string-prototype-replace.js +++ b/tests/jerry/string-prototype-replace.js @@ -32,6 +32,11 @@ assert ("1234".replace(23, 32) === "1324"); assert ("abcabc".replace(/bc/, ":") === "a:abc"); assert ("axbcxx".replace(/x*/g, ":") === ":a::b:c::"); +assert ("".replace(/|/g,"஻") === "஻"); +assert ("஻BB8B@abXde^".replace(/a/g,"$஻Bce((/a%") === "஻BB8B@$஻Bce((/a%bXde^"); +assert ("abcab".replace(/a/g,"˙Ł$Đ") === "˙Ł$Đbc˙Ł$Đb"); +assert ("˙Ł$Đbc˙Ł$Đb".replace("Ł$","ab") === "˙abĐbc˙Ł$Đb"); + assert (String.prototype.replace.call (12321, /2/g, ".") === "1.3.1"); try