summaryrefslogtreecommitdiff
path: root/src/ninep/events.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-30 23:05:57 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:17 -0300
commitd5054831d48c8cf400383ad8d842462bf2c203f8 (patch)
treea21515fd41f5e0448547b40312a4e443e8edcd77 /src/ninep/events.zig
parenta628330543d1c2a0b29062036f23b1c74e4ccc6e (diff)
downloadpardes-d5054831d48c8cf400383ad8d842462bf2c203f8.tar.gz
pardes-d5054831d48c8cf400383ad8d842462bf2c203f8.zip
/index and the log escape a control byte, DEL or C1 in a name as \xNN, as they do a byte not UTF-8, so the name decodes to what it is
A control byte in a name read as a space, so /index could not be decoded back to the name the name file now accepts (\x07 and a space read the same). Every byte a name holds that is not printable UTF-8 is now \xNN there; a message's text keeps spaces. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/events.zig')
-rw-r--r--src/ninep/events.zig25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 1ffbaab9..9d59e6cc 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -337,9 +337,10 @@ fn sanitize(record: []const u8, out: []u8) []u8 {
/// `text` as one line of UTF-8 a reader can split and decode, as /log and
/// /index show names: a backslash is `\\`, a newline `\n` (a name with one
-/// stays readable as what it is, not run into the next), any other control
-/// character, DEL or C1 control (U+0080-U+009F) a space, and a byte that
-/// is not UTF-8 `\xNN`. `out` of 4 bytes a byte of `text` holds it all.
+/// stays readable as what it is, not run into the next), and any other
+/// control character, DEL, C1 control (U+0080-U+009F) or byte that is not
+/// UTF-8 `\xNN`, so a name read there decodes to the bytes it is. `out` of
+/// 4 bytes a byte of `text` holds it all.
pub fn shown(text: []const u8, out: []u8) []u8 {
return shownAs(text, out, true);
}
@@ -365,8 +366,15 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
if (c < ' ' or c == 0x7f) {
- out[w] = ' ';
- w += 1;
+ // A name's (escape_newline) is `\xNN`, so it reads back as the
+ // byte it was; a message's a space.
+ if (escape_newline) {
+ _ = std.fmt.bufPrint(out[w..], "\\x{x:0>2}", .{c}) catch break;
+ w += 4;
+ } else {
+ out[w] = ' ';
+ w += 1;
+ }
i += 1;
continue;
}
@@ -378,6 +386,13 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
if (n == 2 and c == 0xC2 and body[i + 1] <= 0x9F) {
+ if (escape_newline) {
+ if (w + 8 > out.len) break;
+ _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{body[i + 1]}) catch break;
+ w += 8;
+ i += 2;
+ continue;
+ }
out[w] = ' ';
w += 1;
i += 2;