Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Disdjj
Copy link
Contributor

@Disdjj 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
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This comment was marked as outdated.

@Disdjj Disdjj requested a review from kevwan July 28, 2025 03:42
@kevwan kevwan self-assigned this Jul 30, 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
@kevwan kevwan added this to the v1.9.0 milestone Jul 31, 2025
@kevwan kevwan requested a review from Copilot July 31, 2025 11:49
Copy link
Contributor

Copilot AI left a 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 doMarshalJson function using json.NewEncoder with SetEscapeHTML(false)
  • Updated doWriteJson to use the new marshaling function instead of json.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}},

@kevwan kevwan added this pull request to the merge queue Jul 31, 2025
Merged via the queue into zeromicro:master with commit 93c11a7 Jul 31, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants