Skip to content

Fix #1474: Preserve Unicode escapes in verbose JSON output#1846

Open
kkkkwe4324 wants to merge 2 commits into
httpie:masterfrom
kkkkwe4324:master
Open

Fix #1474: Preserve Unicode escapes in verbose JSON output#1846
kkkkwe4324 wants to merge 2 commits into
httpie:masterfrom
kkkkwe4324:master

Conversation

@kkkkwe4324
Copy link
Copy Markdown

Submission Report: Fix #1474 (Preserve Escaped Unicode in Verbose Request Body)

  1. Background
    Issue http -v should show escaped Unicode as-is #1474 reports that HTTPie reformats request JSON in verbose output, so escaped Unicode (for example, \u3042) is shown as the decoded character (あ). This makes verbose output inconsistent with the serialized request payload.(http -v should show escaped Unicode as-is #1474)

Key clarifications:

#814 mainly addressed the semantics and behavior explanation of :=.
#1474 is about display fidelity in verbose request output, not request semantics.
image

  1. Solution
    Goal: fix consistency of request JSON display in verbose mode only, without changing response formatting behavior or request semantics.

Implementation:
In [streams.py:219] inside process_body, JSON request bodies for HTTPRequest with MIME application/json are passed through directly.
This bypasses JSON reformatting for request-body display only.
Response-side pretty formatting behavior is intentionally unchanged.
Added a focused regression test to ensure verbose request output preserves \u3042.

Code locations:
Logic change: [streams.py:220]
Regression test:[test_output.py:337]
屏幕截图 2026-05-12 232128
屏幕截图 2026-05-12 232140

  1. Verification (Commands and Results)
    3.1 Behavior verification command
    python.exe -m httpie --verbose --offline --pretty=format example.org a:=@tmp-1474.json
    Conclusion: verbose request body correctly preserves escaped Unicode.
屏幕截图 2026-05-12 232429

3.2 New regression test command
Result summary: Passed
image

3.3 Related regression test command
Result summary:Passed
屏幕截图 2026-05-12 233922

  1. Impact Scope and Risk
    Scope:

Only request-side JSON body rendering in verbose/pretty output path.
Not affected:

Request semantics (including := parsing semantics) remain unchanged.
Response JSON pretty formatting remains unchanged.
No regressions observed in related encoding test scenarios.

  1. Why ":=" doesn't send non-ascii characters as "raw" #814 Did Not Resolve http -v should show escaped Unicode as-is #1474
    Issue ":=" doesn't send non-ascii characters as "raw" #814 and issue http -v should show escaped Unicode as-is #1474 are related but not the same problem.

#814 focused on the semantics of := (raw JSON field input) and whether non-ASCII content should be sent as UTF-8 bytes or escaped code points.
#1474 focuses on verbose output fidelity: whether http -v should display the request body exactly as serialized (for example, "\u3042"), instead of showing a decoded character ("あ").
In short:

#814 is about input semantics and send behavior.
#1474 is about request-body display consistency in verbose mode.
After #814, users could still observe in #1474 that verbose request output did not preserve escaped Unicode as-is, even when the serialized request body contained escape sequences. This PR addresses that specific gap.

6. Scope of This PR
This PR intentionally limits changes to request JSON body rendering in verbose/pretty output path:

Preserve escaped Unicode sequences for JSON request bodies in verbose output.
Keep response-side JSON pretty formatting behavior unchanged.
Do not alter request parsing semantics for :=.
This narrow scope minimizes regression risk while directly resolving #1474.

kkkkwe4324 added 2 commits May 12, 2026 23:05
- Modified json.py formatter to keep \u escapes for request bodies
- Added test_verbose_preserves_unicode_escape() in test_output.py
- Response body remains human-readable (decoded)

Before: http -v showed 'あ' instead of '\u3042'
After:  http -v shows '\u3042' correctly
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.

http -v should show escaped Unicode as-is

1 participant