aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-22 16:34:41 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-22 16:34:41 -0500
commite0706bc707ea6a8be86cee9fde21971cde3d7a42 (patch)
tree4f99c54a00ca88c87ea4e57ccbf2f644fc9c4bbe /src/stdlib
parenta529e344c07a064de1391c1a4bf354fe1a95707d (diff)
Bugfix for infinite loop in text.replace("", ...) with empty string
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/text.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 8e800c8a..febcafce 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -1135,6 +1135,7 @@ Text_t Text$translate(Text_t text, Table_t translations) {
struct {
Text_t target, replacement;
} *entry = replacement_list.data + r * replacement_list.stride;
+ if (entry->target.length <= 0) continue;
TextIter_t target_state = NEW_TEXT_ITER_STATE(entry->target);
if (_matches(&text_state, &target_state, i)) {
if (i > span_start) result = concat2(result, Text$slice(text, I(span_start + 1), I(i)));
@@ -1156,6 +1157,7 @@ Text_t Text$translate(Text_t text, Table_t translations) {
public
Text_t Text$replace(Text_t text, Text_t target, Text_t replacement) {
+ if (target.length <= 0) return text;
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), target_state = NEW_TEXT_ITER_STATE(target);
Text_t result = EMPTY_TEXT;
int64_t span_start = 0;