fix(bonfire): strip control characters from error blocks, process views and tables

- bonfire.Sanitize (additive), moved from diary's console channel: tab
  kept, CR and LF to a space, every other control character dropped
- applied before styling to every error-block line (message,
  explanation, Try lines, -v chain), process-view item names and errors,
  the current item of spinner and progress, failure lines, and table
  headers and cells in both layouts
- diary's console handler calls bonfire.Sanitize; README and the
  writing-commands page say so (WR-05)
This commit is contained in:
Jakub Zych
2026-10-22 02:31:55 +02:00
parent 39677f1819
commit a9025c0d12
10 changed files with 181 additions and 51 deletions

View File

@@ -295,3 +295,26 @@ func TestPrintAbove(t *testing.T) {
t.Errorf("the spinner did not run as a live view:\n%s", got)
}
}
// TestTableStripsControl (WR-05): table headers and cells carrying control
// sequences print without them, boxed with color on a terminal and as
// tab-separated lines off one.
func TestTableStripsControl(t *testing.T) {
headers := []string{"Name\x1b]0;pwned\x07", "Scope"}
rows := [][]string{{"token \x1b[2J one", "journal\x07.posts"}}
for _, tty := range []bool{true, false} {
var out bytes.Buffer
c := newConsole(strings.NewReader(""), &out, &out, noEnv, boolPtr(tty), boolPtr(tty))
c.setGlobals(Globals{Color: ColorAlways})
c.Table(headers, rows)
got := out.String()
if bad := carriesInjected(got); bad != "" {
t.Errorf("terminal %v: table carries %q:\n%q", tty, bad, got)
}
for _, want := range []string{"Name", "token", "one", "journal", "posts"} {
if !strings.Contains(got, want) {
t.Errorf("terminal %v: table lacks %q:\n%q", tty, want, got)
}
}
}
}