chore(slogutil): ensure quoting of empty and confusing log values (#10236)

Clearer parsing (also for humans)
This commit is contained in:
Jakob Borg
2025-08-10 08:23:23 +00:00
committed by GitHub
parent 34f61ce464
commit 29e10e00d2
2 changed files with 4 additions and 1 deletions
+2 -1
View File
@@ -116,6 +116,7 @@ func expandAttrs(prefix string, a slog.Attr) []slog.Attr {
}
func appendAttr(sb *strings.Builder, prefix string, a slog.Attr, attrCount *int) {
const confusables = ` "()[]{},`
if a.Key == "" {
return
}
@@ -127,7 +128,7 @@ func appendAttr(sb *strings.Builder, prefix string, a slog.Attr, attrCount *int)
sb.WriteString(a.Key)
sb.WriteRune('=')
v := a.Value.Resolve().String()
if strings.ContainsAny(v, ` "()`) {
if v == "" || strings.ContainsAny(v, confusables) {
v = strconv.Quote(v)
}
sb.WriteString(v)