fix: guarantee progress in find_all_ranges when pattern is shorter than a utf8 sequence

This commit is contained in:
CJ van den Berg 2025-11-26 10:22:04 +01:00
parent 99f9f95dbc
commit 74e7406034
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 6 additions and 2 deletions

View file

@ -989,7 +989,11 @@ const Node = union(enum) {
.case_folded => {
const input_consume_size = @min(ctx.buf.len - ctx.rest.len, input.len);
var writer = std.Io.Writer.fixed(ctx.buf[ctx.rest.len..]);
const folded = unicode.case_folded_write_partial(&writer, input[0..input_consume_size]) catch return error.WriteFailed;
var folded = unicode.case_folded_write_partial(&writer, input[0..input_consume_size]) catch return error.WriteFailed;
if (folded.len == 0) {
try writer.writeByte(input[0]);
folded = input[0..1];
}
ctx.rest = ctx.buf[0 .. ctx.rest.len + folded.len];
input = input[folded.len..];
},

View file

@ -212,7 +212,7 @@ const Utf8PartialIterator = struct {
return null;
}
const cp_len = utf8ByteSequenceLength(it.bytes[it.end]) catch unreachable;
const cp_len = utf8ByteSequenceLength(it.bytes[it.end]) catch return null;
if (it.end + cp_len > it.bytes.len) {
return null;
}