From e6e81a6bc544c5ab5a47c21d85e6868020031abb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 01:18:56 -0300 Subject: regexp: a class's range may end at \xff: mvzr counted `c1..c2 + 1` in a u8, which overflowed at 0xff (a panic in a safe build, a loop past its bounds in a fast one), so `[\x80-\xff]` in any search, an address, s or S, a plumbing rule, took the editor down; build.zig's patch of mvzr widens the count to usize, beside its other patches (one occurrence, checked); found writing the plumber's rules, whose classes for UTF-8 names the design record wrote as \x80-\xff; test: a class of a-z and the high bytes finds café, [\xff-\xff] compiles; the changelog says so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/CHANGELOG.md | 4 ++++ src/regexp.zig | 8 ++++++++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index d4d237f0..ed8993c9 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- A search with a class whose range ends at `\xff` (`[\x80-\xff]`, in an + address, `s`, a plumbing rule) no longer takes the editor down: mvzr + counted the range past a byte's end. + - The plumber, Plan 9's, is in the session: `plumb/rules` holds its rules in plumb(6)'s language (rule sets of `object verb arg` lines, variables, `include`, `matches` over the whole text or around a click, diff --git a/src/regexp.zig b/src/regexp.zig index 7bcbceff..87fc51d6 100644 --- a/src/regexp.zig +++ b/src/regexp.zig @@ -595,6 +595,14 @@ test "a \\x without two hex digits is refused, not handed to mvzr to panic on" { try std.testing.expectEqual(@as(usize, 1), (try rx.find("xA", 0, 1, 2)).?.start); } +test "a class's range may end at \\xff: UTF-8's high bytes as one class" { + var rx = try Regex.compile("[a-z\\x80-\\xff]+"); + const text = "-- café --"; + const m = (try rx.find(text, 0, text.len, text.len)).?; + try std.testing.expectEqualStrings("café", text[m.start..m.end]); + _ = try Regex.compile("[\\xff-\\xff]"); +} + test "a repeat inside a group gives back to what follows the group" { const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize }; for ([_]Case{ -- cgit v1.3