[pdata/pcommon] Remove HTML-escaping of special chars when converting Map and Slice Values to JSON strings#14670
Conversation
b51b91a to
84b80d1
Compare
… Map and Slice Values to JSON strings
84b80d1 to
611907a
Compare
|
We added a new dependency |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14670 +/- ##
=======================================
Coverage 91.81% 91.82%
=======================================
Files 680 680
Lines 43043 43043
=======================================
+ Hits 39522 39525 +3
+ Misses 2449 2447 -2
+ Partials 1072 1071 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mx-psi
left a comment
There was a problem hiding this comment.
Thanks for your PR, can we confirm first with the specification what the recommended approach is for this? There was a recent change (see open-telemetry/opentelemetry-specification/pull/4848) that established some guidance on representing complex attributes, I would like to understand what the preferred approach is so that the Collector is as consistent as feasible with SDKs
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
|
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Description
Value.AsString() produces inconsistent output for string values containing HTML-special characters (<, >, &). When the Value is of type ValueTypeStr, the raw string is returned with no escaping. However, when the Value is of type ValueTypeMap or ValueTypeSlice, the standard library's json.Marshal HTML-escapes those characters to their Unicode escape sequences (\u003c, \u003e, \u0026).
This fix replaces encoding/json's json.Marshal with github.com/goccy/go-json's json.MarshalWithOption using the json.DisableHTMLEscape() option, so that Map and Slice values are serialized to JSON without HTML escaping, consistent with the behavior of plain string values.
Link to tracking issue
Fixes #14662
Testing
Added two new test cases to TestValueAsString:
map_with_html_chars: verifies that a Map containing the string html&value is serialized as {"key":"html&value"} (not {"key":"\u003cb\u003ehtml\u0026value\u003c/b\u003e"}).
slice_with_html_chars: verifies that a Slice containing strings link and a]>b&c is serialized as ["link","a]>b&c"].
All existing tests in pdata/pcommon continue to pass.
Documentation
A changelog entry was added at .chloggen/fix-value-asstring-html-escaping.yaml describing the bug fix for the pkg/pdata component.