mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
## Description
`pcommon.Value.AsString` uses `json.Marshal` for `ValueTypeMap` and
`ValueTypeSlice`, which HTML-escapes `<`, `>`, and `&` into `\u003c`,
`\u003e`, and `\u0026`. This is inconsistent with `ValueTypeStr`, which
returns the raw string, and corrupts structured log bodies whose content
happens to contain those characters.
```
"<".AsString() -> "<"
["<"].AsString() -> ["\u003c"] // surprising
{"key":"<"}.AsString() -> {"key":"\u003c"} // surprising
```
Switch to `json.Encoder` with `SetEscapeHTML(false)` so that maps and
slices serialize the same way strings do.
Closes #14662
## Link to tracking Issue
#14662
## Testing
Added `map_with_html_characters` and `slice_with_html_characters`
sub-tests to `TestValueAsString`. `go test ./pcommon/... -run
TestValueAsString` passes (14/14).
## Documentation
.chloggen entry added.
---------
Signed-off-by: alliasgher <[email protected]>
Signed-off-by: Ali <[email protected]>