html debug page: make spew output mangling more precise

Previously, it also ate anything in parens in string literals,
such as in “Donation (200 CHF)”!
This commit is contained in:
Michael Stapelberg
2020-09-10 09:50:23 +02:00
parent c090eb57c2
commit b3cc8c1cc3

View File

@@ -30,7 +30,7 @@ import (
var (
fieldNameRe = regexp.MustCompile(`<br>(&nbsp;)*([^:]+):`)
stringLiteralRe = regexp.MustCompile(`"([^"]*)"`)
parenRe = regexp.MustCompile(`\(([^)]+)\)&nbsp;`)
typeInfoRe = regexp.MustCompile(`(<br>(&nbsp;)*([^:]+):&nbsp;)[^"{]+`)
)
var tmpl = template.Must(template.New("").Parse(`<!DOCTYPE html>
@@ -203,7 +203,7 @@ func debugHTML(w http.ResponseWriter, r *http.Request, prefix string, qrch *qrbi
sp := spew.Sdump(vars...)
sp = strings.ReplaceAll(sp, "\n", "<br>")
sp = strings.ReplaceAll(sp, " ", "&nbsp;")
sp = parenRe.ReplaceAllString(sp, "")
sp = typeInfoRe.ReplaceAllString(sp, "$1")
sp = stringLiteralRe.ReplaceAllStringFunc(sp, func(stringLiteral string) string {
return `<span class="stringliteral">` + stringLiteral + "</span>"
})