fix(bonfire): replace invalid UTF-8 before the control scan in Sanitize (IN-08, quick-261028-rqd)

This commit is contained in:
Jakub Zych
2026-10-28 20:21:19 +01:00
parent 825a3fd2da
commit 8476a65aa0
3 changed files with 26 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"testing"
"unicode/utf8"
)
// TestExitCodes: Execute returns 0 on success, 1 on a failure and 2 on an
@@ -323,9 +324,21 @@ func TestSanitize(t *testing.T) {
"a\x1b]0;title\x07b": "a]0;titleb",
"nul\x00 and del\x7f and \x01": "nul and del and ",
"boom\x1b[2Jclear": "boom[2Jclear",
// IN-08: invalid UTF-8 becomes U+FFFD, so a raw 8-bit C1 byte
// such as 0x9b (CSI) never reaches the terminal.
"a\x9b31mb": "a\uFFFD31mb",
"\x9b": "\uFFFD",
"\xffok": "\uFFFDok",
} {
if got := Sanitize(in); got != want {
t.Errorf("Sanitize(%q) = %q, want %q", in, got, want)
}
if got := Sanitize(in); !utf8.ValidString(got) {
t.Errorf("Sanitize(%q) = %q is not valid UTF-8", in, got)
}
}
clean := "plain ok"
if got := Sanitize(clean); got != clean {
t.Errorf("Sanitize(%q) = %q, want it unchanged", clean, got)
}
}