fix(commands): substitute parsing bug

There was a bug in the parsing logic that caused a substitution
command like `s/typo/correction` to crash the bot.

Correct command is of course `s/typo/correction/`, but now it at least
shouldn't crash.
This commit is contained in:
Jacob Jonsson 2026-03-11 01:19:33 +01:00
parent 4e11cc9ea1
commit 8b15398196
Signed by: Jassob
GPG key ID: 7E30B9B047F7202E
2 changed files with 33 additions and 12 deletions

View file

@ -61,9 +61,11 @@ pub const Parser = struct {
//
// Returns a new parser window that starts after idx and the
// extracted byte slice.
pub fn take_until_char(self: *const Parser, c: u8) struct { Parser, []const u8 } {
const idx = std.mem.indexOfScalar(u8, self.rest, c) orelse unreachable;
return .{ self.seek(idx), self.rest[0..idx] };
pub fn take_until_char(self: *const Parser, c: u8) ?struct { Parser, []const u8 } {
if (std.mem.indexOfScalar(u8, self.rest, c)) |idx| {
return .{ self.seek(idx), self.rest[0..idx] };
}
return null;
}
// Take the current character and advance the parser one step.