diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 09:52:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:16 -0300 |
| commit | a72d0c6650242a9b02858de7020e9a4ae387ebba (patch) | |
| tree | 8f3d44da4e32ad85bf7abf52c2852dbe62a7904f /src/ninep/events.zig | |
| parent | ad3403adb72e3457eb76d6b3fc91cf8df3d738ae (diff) | |
| download | pardes-a72d0c6650242a9b02858de7020e9a4ae387ebba.tar.gz pardes-a72d0c6650242a9b02858de7020e9a4ae387ebba.zip | |
A name shows its own backslash as \\, and a terminal tag never carries a raw newline
With `\n` for a newline and `\xNN` for a bad byte, a name holding a
backslash and an n read back as one holding a newline. Names in /index,
the log and a terminal's tag now double their own backslashes; and a
terminal's directory with a newline no longer breaks its tag.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/events.zig')
| -rw-r--r-- | src/ninep/events.zig | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 3da6f723..8b8f8637 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -358,10 +358,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 newline is `\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. +/// /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. pub fn shown(text: []const u8, out: []u8) []u8 { return shownAs(text, out, true); } @@ -372,6 +372,14 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 { const body = text; while (i < body.len and w + 4 <= out.len) { const c = body[i]; + // A name's own backslash is `\\`, so `\n` and `\xNN` read back as + // the escapes they are, never as a name that held them. + if (c == '\\' and escape_newline) { + @memcpy(out[w..][0..2], "\\\\"); + w += 2; + i += 1; + continue; + } if (c == '\n' and escape_newline) { @memcpy(out[w..][0..2], "\\n"); w += 2; @@ -1312,6 +1320,9 @@ test "a record is one line of UTF-8: DEL and C1 are spaces, bytes not UTF-8 are var out: [64]u8 = undefined; var name: [64]u8 = undefined; try testing.expectEqualStrings("/tmp/two\\nlines", shown("/tmp/two\nlines", &name)); + // A backslash of the name's own is doubled: `\n` in a name differs from + // a newline in one. + try testing.expectEqualStrings("/tmp/a\\\\nb", shown("/tmp/a\\nb", &name)); try testing.expectEqualStrings("msg - a b c \\xff d\n", sanitize("msg - a\x7fb\xc2\x85c \xff d\n", &out)); try testing.expectEqualStrings("msg - caf\xc3\xa9\n", sanitize("msg - caf\xc3\xa9\n", &out)); } |
