MCPcopy Create free account
hub / github.com/cli/cli / TestUntrusted_survivesJSONDecode

Function TestUntrusted_survivesJSONDecode

pkg/iostreams/untrusted_test.go:56–64  ·  view source on GitHub ↗

The showcase property: an Untrusted struct field is populated by json.Unmarshal with provenance intact, so printing it later sanitizes even though the bytes arrived through a JSON decode.

(t *testing.T)

Source from the content-addressed store, hash-verified

54// json.Unmarshal with provenance intact, so printing it later sanitizes even
55// though the bytes arrived through a JSON decode.
56func TestUntrusted_survivesJSONDecode(t *testing.T) {
57 var entry struct {
58 Content Untrusted `json:"content"`
59 }
60 payload := `{"content":"log\u001b[31mline"}`
61 require.NoError(t, json.Unmarshal([]byte(payload), &entry))
62 assert.Equal(t, "log\x1b[31mline", entry.Content.Raw())
63 assert.NotContains(t, entry.Content.String(), esc)
64}
65
66func TestUntrusted_jsonRoundTrip(t *testing.T) {
67 u := NewUntrusted("x\x1b[0m")

Callers

nothing calls this directly

Calls 3

EqualMethod · 0.80
RawMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected