Files
webterm/go/webterm/normalize_test.go
T
GitHub Copilot 674e62d983 refactor: upgrade go-te to v0.1.0, remove C1 normalization
go-te v0.1.0 fixes the ByteStream C1 bug (Latin-1 fallback for
invalid UTF-8 bytes), so NormalizeC1Controls is no longer needed.

Removed:
- NormalizeC1Controls function and its tests/fuzz target
- utf8Buffer field from TerminalSession and DockerExecSession
- C1BUG.md (fix shipped upstream)

The handleOutput pipeline now does: FilterDA → replay → tracker → connector
(was: FilterDA → NormalizeC1 → replay → tracker → connector)

All tests pass with -race. 13 fuzz targets remain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-14 16:40:28 +00:00

56 lines
1.6 KiB
Go

package webterm
import (
"bytes"
"testing"
)
func TestFilterDASequencesCompleteAndPartial(t *testing.T) {
data := []byte("a\x1b[?1;10;0cb")
filtered, buffer := FilterDASequences(data, nil)
if string(buffer) != "" {
t.Fatalf("expected empty buffer, got %q", string(buffer))
}
if string(filtered) != "ab" {
t.Fatalf("unexpected filtered output: %q", string(filtered))
}
part1, partBuffer := FilterDASequences([]byte("x\x1b[?1;10"), nil)
if string(part1) != "x" {
t.Fatalf("unexpected part1 output: %q", string(part1))
}
if string(partBuffer) == "" {
t.Fatalf("expected buffered partial sequence")
}
part2, partBuffer2 := FilterDASequences([]byte(";0cy"), partBuffer)
if string(partBuffer2) != "" {
t.Fatalf("expected empty buffer after completion")
}
if string(part2) != "y" {
t.Fatalf("unexpected part2 output: %q", string(part2))
}
}
func FuzzFilterDASequences(f *testing.F) {
f.Add([]byte("a\x1b[?1;10;0cb"), []byte{})
f.Add([]byte("plain text"), []byte{})
f.Add([]byte{0x1b, '[', '?'}, []byte{})
f.Add([]byte(";0cy"), []byte("\x1b[?1;10"))
f.Add([]byte("\x1b[>0c\x1b[=1c"), []byte{})
f.Add([]byte{}, []byte{0x1b})
f.Add([]byte("no escape"), []byte{})
f.Fuzz(func(t *testing.T, data []byte, buffer []byte) {
out, remaining := FilterDASequences(data, buffer)
_ = out
// Remaining should be empty or a partial escape sequence starting with ESC
if len(remaining) > 0 && remaining[0] != 0x1b {
t.Errorf("remaining buffer doesn't start with ESC: %q", remaining)
}
// Complete DA sequences should not appear in output
if bytes.Contains(out, []byte("\x1b[?1;10;0c")) {
t.Errorf("DA sequence leaked through filter")
}
})
}