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

Function TestHTTPClientSanitizeControlCharactersC1

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

Source from the content-addressed store, hash-verified

466}
467
468func TestHTTPClientSanitizeControlCharactersC1(t *testing.T) {
469 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
470 issue := Issue{
471 Title: "\xC2\x9B[31mRed Title\xC2\x9B[0m",
472 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",
473 Author: Author{
474 ID: "1",
475 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",
476 Login: "monalisa\xC2\xA1",
477 },
478 }
479 responseData, _ := json.Marshal(issue)
480 w.Header().Set("Content-Type", "application/json; charset=utf-8")
481 fmt.Fprint(w, string(responseData))
482 }))
483 defer ts.Close()
484
485 client, err := NewHTTPClient(HTTPClientOptions{})
486 require.NoError(t, err)
487 req, err := http.NewRequest("GET", ts.URL, nil)
488 require.NoError(t, err)
489 res, err := client.Do(req)
490 require.NoError(t, err)
491 body, err := io.ReadAll(res.Body)
492 res.Body.Close()
493 require.NoError(t, err)
494 var issue Issue
495 err = json.Unmarshal(body, &issue)
496 require.NoError(t, err)
497 assert.Equal(t, "^[[31mRed Title^[[0m", issue.Title)
498 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)
499 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)
500 assert.Equal(t, "monalisa¡", issue.Author.Login)
501}
502
503func TestNewHTTPClientTelemetryDisabler(t *testing.T) {
504 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