Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,16 @@ func wrapProxy(err error) Error {
}
}

// htmlEscaper matches the escaping done in [html/template] for text and quoted
// attributes, which is slightly more than what [html.EscapeString] does.
var htmlEscaper = strings.NewReplacer(
"\x00", "\uFFFD",
`"`, """, // """ is shorter than """.
`&`, "&",
`'`, "'", // "'" is shorter than "'" and apos was not in HTML until HTML5.
`+`, "+",
`<`, "&lt;",
`>`, "&gt;",
`"`, "&#34;", // "&#34;" is shorter than "&quot;".
)

// DebugReport formats the underlying error for display
Expand Down
4 changes: 2 additions & 2 deletions trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestProxyErrorDebugReport(t *testing.T) {
err: proxyError{
TraceErr: &TraceErr{
Err: &TraceErr{
Err: &BadParameterError{Message: `a < b & c > d "e"`},
Err: &BadParameterError{Message: `a < b & c > d "e" + '` + "\x00" + `'`},
Traces: innerTraces,
Fields: map[string]interface{}{"k<ey": "v<al&ue>"},
Messages: []string{`<script>alert("xss")</script>`},
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestTraceErrDebugReport(t *testing.T) {
{
name: "html special characters",
err: &TraceErr{
Err: &BadParameterError{Message: `a < b & c > d "e"`},
Err: &BadParameterError{Message: `a < b & c > d "e" + '` + "\x00" + `'`},
Traces: traces,
Fields: map[string]interface{}{"k<ey": "v<al&ue>"},
Messages: []string{`<script>alert("xss")</script>`},
Expand Down
Loading