MCPcopy Index your code
hub / github.com/cli/cli / TestHTTPClientSanitizeControlCharactersC1

Function TestHTTPClientSanitizeControlCharactersC1

api/http_client_test.go:283–316  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

281}
282
283func TestHTTPClientSanitizeControlCharactersC1(t *testing.T) {
284 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
285 issue := Issue{
286 Title: "\xC2\x9B[31mRed Title\xC2\x9B[0m",
287 Body: "80\xC2\x80 81\xC2\x81 82\xC2\x82 83\xC2\x83 84\xC2\x84 85\xC2\x85 86\xC2\x86 87\xC2\x87 88\xC2\x88 89\xC2\x89 8A\xC2\x8A 8B\xC2\x8B 8C\xC2\x8C 8D\xC2\x8D 8E\xC2\x8E 8F\xC2\x8F",
288 Author: Author{
289 ID: "1",
290 Name: "90\xC2\x90 91\xC2\x91 92\xC2\x92 93\xC2\x93 94\xC2\x94 95\xC2\x95 96\xC2\x96 97\xC2\x97 98\xC2\x98 99\xC2\x99 9A\xC2\x9A 9B\xC2\x9B 9C\xC2\x9C 9D\xC2\x9D 9E\xC2\x9E 9F\xC2\x9F",
291 Login: "monalisa\xC2\xA1",
292 },
293 }
294 responseData, _ := json.Marshal(issue)
295 w.Header().Set("Content-Type", "application/json; charset=utf-8")
296 fmt.Fprint(w, string(responseData))
297 }))
298 defer ts.Close()
299
300 client, err := NewHTTPClient(HTTPClientOptions{})
301 require.NoError(t, err)
302 req, err := http.NewRequest("GET", ts.URL, nil)
303 require.NoError(t, err)
304 res, err := client.Do(req)
305 require.NoError(t, err)
306 body, err := io.ReadAll(res.Body)
307 res.Body.Close()
308 require.NoError(t, err)
309 var issue Issue
310 err = json.Unmarshal(body, &issue)
311 require.NoError(t, err)
312 assert.Equal(t, "^[[31mRed Title^[[0m", issue.Title)
313 assert.Equal(t, "80^@ 81^A 82^B 83^C 84^D 85^E 86^F 87^G 88^H 89^I 8A^J 8B^K 8C^L 8D^M 8E^N 8F^O", issue.Body)
314 assert.Equal(t, "90^P 91^Q 92^R 93^S 94^T 95^U 96^V 97^W 98^X 99^Y 9A^Z 9B^[ 9C^\\ 9D^] 9E^^ 9F^_", issue.Author.Name)
315 assert.Equal(t, "monalisa¡", issue.Author.Login)
316}
317
318func TestNewHTTPClientTelemetryDisabler(t *testing.T) {
319 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

DoMethod · 0.95
NewHTTPClientFunction · 0.85
EqualMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected