-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(debug printer): Handle HTML encodings correctly (#530)
Signed-off-by: Alexander Dahmen <[email protected]>
- Loading branch information
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,28 @@ func fixtureHTTPRequest(mods ...func(req *http.Request)) *http.Request { | |
return request | ||
} | ||
|
||
func fixtureHTTPRequestUnescaped(mods ...func(req *http.Request)) *http.Request { | ||
testBody, err := json.Marshal(map[string]string{"key": "value"}) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
request, err := http.NewRequest("GET", "http://example.com/v2/projects?limit=50&member=User.Name%40stackit.cloud", bytes.NewReader(testBody)) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
request.Header.Set("Content-Type", "application/json") | ||
request.Header.Set("Accept", "application/json") | ||
request.Header.Set("Content-Length", "15") | ||
|
||
for _, mod := range mods { | ||
mod(request) | ||
} | ||
|
||
return request | ||
} | ||
|
||
func fixtureHTTPResponse(mods ...func(resp *http.Response)) *http.Response { | ||
testBody, err := json.Marshal(map[string]string{"key": "value"}) | ||
if err != nil { | ||
|
@@ -402,6 +424,16 @@ func TestBuildDebugStrFromHTTPRequest(t *testing.T) { | |
}, | ||
isValid: true, | ||
}, | ||
{ | ||
description: "unescaped test", | ||
inputReq: fixtureHTTPRequestUnescaped(), | ||
expected: []string{ | ||
"request to http://example.com/v2/projects?limit=50&[email protected]: GET HTTP/1.1", | ||
"request headers: [Accept: application/json, Content-Length: 15, Content-Type: application/json]", | ||
"request body: [key: value]", | ||
}, | ||
isValid: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
|