Skip to content

Commit

Permalink
fix: crash when input line is invalid utf8
Browse files Browse the repository at this point in the history
The input is passed to normalizer.nfd. Previously it was assumed that
the input was valid utf8. If the input contained invalid bytes, zf would
panic and exit.

This is a temporary workaround. A future commit will remove zyglyph
entirely and this will no longer be an issue.

Closes #58
  • Loading branch information
natecraddock committed Feb 6, 2024
1 parent 4dbf46d commit 50e3a8b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ pub fn main() anyerror!void {
const buf = blk: {
var stdin = io.getStdIn().reader();
const buf = try readAll(allocator, &stdin);
break :blk std.mem.trim(u8, (try normalizer.nfd(allocator, buf)).slice, "\n");
if (std.unicode.utf8ValidateSlice(buf)) {
break :blk std.mem.trim(u8, (try normalizer.nfd(allocator, buf)).slice, "\n");
} else break :blk std.mem.trim(u8, buf, "\n");
};

// escape specific delimiters
Expand Down

0 comments on commit 50e3a8b

Please sign in to comment.