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

Function TestHTTPClientSanitizeControlCharactersC1

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

Source from the content-addressed store, hash-verified

368}
369
370func TestHTTPClientSanitizeControlCharactersC1(t *testing.T) {
371 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
372 issue := Issue{
373 Title: "\xC2\x9B[31mRed Title\xC2\x9B[0m",
374 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",
375 Author: Author{
376 ID: "1",
377 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",
378 Login: "monalisa\xC2\xA1",
379 },
380 }
381 responseData, _ := json.Marshal(issue)
382 w.Header().Set("Content-Type", "application/json; charset=utf-8")
383 fmt.Fprint(w, string(responseData))
384 }))
385 defer ts.Close()
386
387 client, err := NewHTTPClient(HTTPClientOptions{})
388 require.NoError(t, err)
389 req, err := http.NewRequest("GET", ts.URL, nil)
390 require.NoError(t, err)
391 res, err := client.Do(req)
392 require.NoError(t, err)
393 body, err := io.ReadAll(res.Body)
394 res.Body.Close()
395 require.NoError(t, err)
396 var issue Issue
397 err = json.Unmarshal(body, &issue)
398 require.NoError(t, err)
399 assert.Equal(t, "^[[31mRed Title^[[0m", issue.Title)
400 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)
401 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)
402 assert.Equal(t, "monalisa¡", issue.Author.Login)
403}
404
405func TestNewHTTPClientTelemetryDisabler(t *testing.T) {
406 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