Skip to content

fix(output): preserve percent characters in JSON output - #40

Open
yeahjack wants to merge 1 commit into
TencentCloud:mainfrom
yeahjack:fix/preserve-percent-json-output
Open

yeahjack wants to merge 1 commit into
TencentCloud:mainfrom
yeahjack:fix/preserve-percent-json-output

Conversation

@yeahjack

@yeahjack yeahjack commented Oct 3, 2026

Copy link
Copy Markdown

Summary

Fixes #39.

Pass serialized JSON to PrintInfof through a constant %s format string so literal percent characters are preserved. Previously, fmt.Sprintf interpreted the JSON as a format string, corrupting text and sometimes producing invalid JSON. For example, {"text":"50%"} became {"data":{"text":"50%!"(MISSING)}}.

Add regression coverage for json and json-pretty, including nested JSON, plain-text fallback data, percent-encoded URLs, literal formatting verbs, percent characters in trace_id/message, valid JSON, and the trailing newline. All fixtures are synthetic and require no authentication or API calls.

The diff is limited to the output fix and its tests.

Validation

Using Go 1.27.1 on Linux:

  • Regression tests fail on the original implementation and pass with this fix
  • go test -count=1 ./internal/output passes
  • go test -race -count=1 ./internal/output passes
  • go vet ./internal/output passes
  • go build -buildvcs=false passes
  • gofmt checks for repository Go files and git diff --check pass

go test ./... was run on both the changed tree and a clean copy of base commit e631b35. Both runs fail the same 39 existing tests in this environment:

  • cmd/event and internal/event/bus: Unix sockets are denied (socket: operation not permitted), causing bus startup tests to fail
  • internal/core/browser: no graphical environment is available
  • internal/core/thttp: TestNewClient makes a live request to https://www.baidu.com/, which hits the existing 3-second timeout here; the test then dereferences a nil response

These unrelated failures are unchanged by this PR. The output package passes in the full-suite run.

@yeahjack
yeahjack marked this pull request as ready for review October 9, 2026 17:51
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.

JSON output corrupts percent characters and can become invalid JSON

1 participant