fix(bonfire): strip control characters from Process's plain item lines and the view's label (WR-14)
This commit is contained in:
@@ -531,11 +531,13 @@ func TestLiveViewPanicUnregisters(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestProcessViewStripsControl (WR-05): an item name and an item error
|
||||
// carrying control sequences render without them.
|
||||
// TestProcessViewStripsControl (WR-05, WR-14): an item name, an item error
|
||||
// and the operation label carrying control sequences render without them,
|
||||
// in the live view and on the plain path (-n on a terminal, forced color
|
||||
// off a terminal).
|
||||
func TestProcessViewStripsControl(t *testing.T) {
|
||||
name := "evil\x1b]0;pwned\x07item"
|
||||
var m tea.Model = newProcessModel(DefaultPalette(), "Pushing", []string{name, "next"})
|
||||
var m tea.Model = newProcessModel(DefaultPalette(), "Push\x1b]0;pwned\x07ing", []string{name, "next"})
|
||||
m, _ = m.Update(tea.WindowSizeMsg{Width: 120, Height: 24})
|
||||
m, _ = m.Update(stepMsg{item: name, state: itemFailed, err: errors.New("rejected \x1b[2J by the remote"), done: 1})
|
||||
m, _ = m.Update(stepMsg{item: "next", state: itemRunning, done: 1})
|
||||
@@ -543,9 +545,42 @@ func TestProcessViewStripsControl(t *testing.T) {
|
||||
if bad := carriesInjected(out); bad != "" {
|
||||
t.Errorf("process view carries %q:\n%q", bad, out)
|
||||
}
|
||||
for _, want := range []string{"evil", "item", "rejected", "by the remote"} {
|
||||
for _, want := range []string{"evil", "item", "rejected", "by the remote", "Push", "ing"} {
|
||||
if !strings.Contains(ansi.Strip(out), want) {
|
||||
t.Errorf("process view lacks %q:\n%q", want, out)
|
||||
}
|
||||
}
|
||||
|
||||
// The plain path: no live view, a colored writer that passes control
|
||||
// sequences through (TestTableStripsControl).
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
tty bool
|
||||
globals Globals
|
||||
}{
|
||||
{"terminal with -n", true, Globals{Color: ColorAlways, NoInteraction: true}},
|
||||
{"no terminal, color forced", false, Globals{Color: ColorAlways}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
c := newConsole(strings.NewReader(""), &buf, &buf, noEnv, boolPtr(tc.tty), boolPtr(tc.tty))
|
||||
c.setGlobals(tc.globals)
|
||||
if c.live() {
|
||||
t.Fatal("the console runs live views; the plain path is not exercised")
|
||||
}
|
||||
err := Process(context.Background(), c, "Push\x1b]0;pwned\x07ing", []string{name}, func(context.Context, string) error { return nil })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := buf.String()
|
||||
if bad := carriesInjected(got); bad != "" {
|
||||
t.Errorf("plain Process line carries %q:\n%q", bad, got)
|
||||
}
|
||||
for _, want := range []string{"evil", "item"} {
|
||||
if !strings.Contains(ansi.Strip(got), want) {
|
||||
t.Errorf("plain Process line lacks %q:\n%q", want, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user