-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(httpx): Resolve HTML escaping issue during JSON serialization #5032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Disdjj
commented
Jul 24, 2025
- Implemented json.Encoder as a replacement for json.Marshal to prevent automatic HTML character escaping
- Introduced the doMarshalJson function to handle JSON serialization logic
- Added comprehensive test cases to validate serialization behavior across various data types
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- Implemented json.Encoder as a replacement for json.Marshal to prevent automatic HTML character escaping - Introduced the doMarshalJson function to handle JSON serialization logic - Added comprehensive test cases to validate serialization behavior across various data types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an HTML escaping issue in JSON serialization by replacing json.Marshal with a custom json.Encoder that disables HTML escaping. This ensures that characters like &, <, and > are not unnecessarily escaped as Unicode sequences in JSON responses.
- Implemented
doMarshalJsonfunction usingjson.NewEncoderwithSetEscapeHTML(false) - Updated
doWriteJsonto use the new marshaling function instead ofjson.Marshal - Added comprehensive test coverage for various data types and URL scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rest/httpx/responses.go | Implements new JSON marshaling function to prevent HTML escaping |
| rest/httpx/responses_test.go | Adds comprehensive test cases for the new marshaling function |
Comments suppressed due to low confidence (1)
rest/httpx/responses_test.go:500
- The map test case has non-deterministic key ordering in JSON output. Consider using a struct with ordered fields or a map with a single key to ensure consistent test results across different Go versions.
args: args{map[string]int{"a": 1, "b": 2}},