From 421a1c3039ed7b75014278fc16269825e7ff1688 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 May 2022 09:34:34 -0700 Subject: [PATCH] =?UTF-8?q?invalid=20utf8=20turns=20into=20=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/terminal/Parser.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index ecdcfff0d..30fe5259a 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -225,9 +225,9 @@ fn next_utf8(self: *Parser, c: u8) ?Action { // We have enough bytes, decode! const bytes = self.intermediates[0..len]; - const rune = std.unicode.utf8Decode(bytes) catch { + const rune = std.unicode.utf8Decode(bytes) catch rune: { log.warn("invalid UTF-8 sequence: {any}", .{bytes}); - return null; + break :rune 0xFFFD; // � }; return Action{ .print = rune }; @@ -534,7 +534,10 @@ test "print: utf8 invalid" { for ("\xC3\x28") |c| a = p.next(c); try testing.expect(p.state == .ground); - try testing.expect(a[0] == null); + try testing.expect(a[0].? == .print); try testing.expect(a[1] == null); try testing.expect(a[2] == null); + + const rune = a[0].?.print; + try testing.expectEqual(try std.unicode.utf8Decode("�"), rune); }