CF-3932 : Stop HTML-escaping <, >, & in -o json output#3398
CF-3932 : Stop HTML-escaping <, >, & in -o json output#3398Paras Negi (paras-negi-flink) wants to merge 2 commits into
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
There was a problem hiding this comment.
Pull request overview
This PR updates the shared pkg/output JSON serialization path so -o json output no longer HTML-escapes <, >, and &, preserving readability for content like SQL statements and placeholder emails.
Changes:
- Replaced
json.Marshalusage with a sharedmarshalJSONhelper that disables HTML escaping. - Updated
TableJSON output to use the shared helper. - Added/updated tests and refreshed one affected integration golden (
api-key list -o json).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/fixtures/output/api-key/7.golden | Updates expected JSON fixture to reflect unescaped <...> values. |
| pkg/output/table.go | Switches table JSON serialization to the shared marshalJSON helper. |
| pkg/output/table_test.go | Adds unit tests ensuring <, >, & are emitted verbatim in JSON output. |
| pkg/output/serialized_output.go | Introduces marshalJSON helper using json.Encoder with SetEscapeHTML(false). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Manual CLI validationLocal CMF ( Before — released
|
|
| switch t.format { | ||
| default: | ||
| out, err := json.Marshal(v) | ||
| out, err := marshalJSON(v) |
There was a problem hiding this comment.
The intention and solution is straightforward, but these 2 functions are high blast-radius functions, and we need to pay additional attention before touching these.
For example, can you please evaluate and check the impact on these Confluent Cloud commands that are still using the old marshal function? What should be updated if we make changes to printCore()?
https://github.com/confluentinc/cli/blob/main/internal/schema-registry/command_configuration_describe.go#L80-L110
|
|
||
| // marshalJSON marshals v to JSON without HTML-escaping <, >, and & (which | ||
| // encoding/json does by default), keeping text like SQL statements readable. | ||
| func marshalJSON(v any) ([]byte, error) { |
There was a problem hiding this comment.
Do we have the similar issue to yaml format?




Release Notes
Breaking Changes
New Features
Bug Fixes
-o jsonoutput no longer HTML-escapes<,>, and&, keeping readable text such as SQL statements intact.Checklist
Whatsection below whether this PR applies to Confluent Cloud, Confluent Platform, or both.Test & Reviewsection below.Blast Radiussection below.What
Both Confluent Cloud and Confluent Platform (shared output package used by every command).
encoding/jsonHTML-escapes<,>, and&by default. Both-o jsonserializers (pkg/output/serialized_output.go,pkg/output/table.go) usedjson.Marshal, mangling any JSON output with those characters (most visibly Flink SQL statements).marshalJSONhelper (json.EncoderwithSetEscapeHTML(false)) that both serializers use. Drop-in forjson.Marshal; YAML path untouched.Blast Radius
-o jsonfor every command now emits<,>,&verbatim instead of their escaped Unicode sequences. Both forms are valid JSON and decode identically, so parsers are unaffected; exact-string matching against the old escaped form would need to match the raw characters.-o yamland human/table output unchanged.References
Test & Review
Environment: local CMF
cmf-app 2.4-SNAPSHOT(HTTP,--cmf.k8s.enabled=false); CLI built from this branch vs releasedconfluent v4.54.0.Manual CLI validation: attached in the comment below.