From df52fae76a3ea0d334969c8093af8528e9eaa9d9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 17 Jan 2023 21:47:38 -0800 Subject: [PATCH] terminal: check OSC parser for tmux 112 sequences from HN Saw this on HN: https://github.com/darrenstarr/VtNetCore/pull/14 I wanted to see if ghostty was vulnerable to it (it is not). But, its a good example of a weird edge case in the wild and I wanted to make sure it was redundantly tested. It looks like we read the "spec" (blog posts, man pages, source of other terminal using tools, etc.) right. --- src/terminal/Parser.zig | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 855ae640e..e8592dd23 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -607,6 +607,28 @@ test "osc: change window title (end in esc)" { } } +// https://github.com/darrenstarr/VtNetCore/pull/14 +// Saw this on HN, decided to add a test case because why not. +test "osc: 112 incomplete sequence" { + var p = init(); + _ = p.next(0x1B); + _ = p.next(']'); + _ = p.next('1'); + _ = p.next('1'); + _ = p.next('2'); + + { + const a = p.next(0x07); + try testing.expect(p.state == .ground); + try testing.expect(a[0].? == .osc_dispatch); + try testing.expect(a[1] == null); + try testing.expect(a[2] == null); + + const cmd = a[0].?.osc_dispatch; + try testing.expect(cmd == .reset_cursor_color); + } +} + test "print: utf8 2 byte" { var p = init(); var a: [3]?Action = undefined;