这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: do not HTML escape JSON output by default #765

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

Merged
merged 2 commits into from
Mar 15, 2025
Merged

Conversation

danielgtaylor
Copy link
Owner

@danielgtaylor danielgtaylor commented Mar 15, 2025

Be default, JSON output is escaped to better support embedding it into HTML. This is extremely unlikely to be needed for HTTP APIs as they have different access patterns. This changes the default behavior to not escape, while letting people who do need the feature set it up in their huma.Config.Formats map as needed.

For example, expected number \u003e= 10 becomes expected number >= 10 after this change.

@Copilot Copilot AI review requested due to automatic review settings March 15, 2025 19:25
Copy link
Contributor

@Copilot 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 changes the default JSON encoding behavior by disabling HTML escaping.

  • Introduces a JSON encoder that disables HTML escaping by default
  • Maintains backward compatibility by allowing users to re-enable escaping via configuration
Comments suppressed due to low confidence (1)

defaults.go:19

  • Consider adding unit tests to verify that HTML escaping is correctly disabled in the DefaultJSONFormat.Marshal function. Ensuring this behavior with tests will help prevent regressions in the future.
enc.SetEscapeHTML(false)

Copy link

codecov bot commented Mar 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.05%. Comparing base (b73e5ef) to head (4c2372c).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #765   +/-   ##
=======================================
  Coverage   93.05%   93.05%           
=======================================
  Files          23       23           
  Lines        5252     5254    +2     
=======================================
+ Hits         4887     4889    +2     
  Misses        313      313           
  Partials       52       52           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danielgtaylor danielgtaylor merged commit b69ebc7 into main Mar 15, 2025
7 checks passed
@danielgtaylor danielgtaylor deleted the fix-json-escape branch March 15, 2025 19:33
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.

1 participant