Sitelet https://web.archive.org/web/20200619110517/https://github.com/jakubroztocil/httpie/issues/813
Skip to content
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

Document JSON-escaping in "=" syntax #813

Open
wataash opened this issue Nov 2, 2019 · 0 comments
Open

Document JSON-escaping in "=" syntax #813

wataash opened this issue Nov 2, 2019 · 0 comments

Comments

@wataash
Copy link

@wataash wataash commented Nov 2, 2019 •

In = syntax,

  • double quotes (")
  • back slashes (\)
  • non-ascii characters

are escaped in json.dumps:

$ http -v httpbin.org/post                                      \
    dquote='\"'                                                 \
    multi-line='line 1\nline 2'                                 \
    non-ascii=あ                                                \
    unicodes='\u3053\u3093\u306b\u3061\u306f\u4e16\u754c'       \
    ;
POST /post HTTP/1.1
...
User-Agent: HTTPie/1.0.3

{
    "dquote": "\\\"",
    "multi-line": "line 1\\nline 2"
    "non-ascii": "あ",
                 ^^^^ actually "\u3042" (not utf-8 representation 0xe38182)
    "unicodes": "\\u3053\\u3093\\u306b\\u3061\\u306f\\u4e16\\u754c",
}

HTTP/1.1 200 OK
...

This behavior should be documented, shouldn't it?

It's also notable that the escaping can be avoided with :=:

$ http -v httpbin.org/post                                   \
    dquote:='"\""'                                           \
    multi-line:='"line 1\nline 2"'                           \
    non-ascii:='"あ"'                                        \
    unicodes:='"\u3053\u3093\u306b\u3061\u306f\u4e16\u754c"' \
    ;
POST /post HTTP/1.1
...
User-Agent: HTTPie/1.0.3

{
    "dquote": "\"",
    "multi-line": "line 1\nline 2",
    "non-ascii": "あ",
                 ^^^^ actually "\u3042" (#814)
    "unicodes": "こんにちは世界"
                ^^^^^^^^^^^^^^^^
                 actually "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c"
}

HTTP/1.1 200 OK
...

(Note that non-ascii characters can't avoid escaping, see #814)

@wataash wataash changed the title How to include newline (\n) in postdata with "=" syntax? Document JSON-escaping in "=" syntax Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.