Skip to content

Use proper quoting in HTTPie shell commands - #29

Merged
ahmadnassri merged 1 commit into
Kong:masterfrom
jkbrzt:master
Mar 17, 2015
Merged

Use proper quoting in HTTPie shell commands#29
ahmadnassri merged 1 commit into
Kong:masterfrom
jkbrzt:master

Conversation

@jkbrzt

Copy link
Copy Markdown
Contributor

This looks like an interesting project 👍 I've noticed a problem with quoting of the shell commands and this pull request fixes that for HTTPie:

Before, the resultant shell command was completely unquoted. This change introduces proper quoting of values and the URL - when necessary.

It uses single quotes which provide "strong quoting" (only nested single quote characters need to be taken care of) and also make the output more readable as double quotes, ubiquitous in JSON, don't require escaping.

Before:

echo"{\"foo\": \"bar\"}"|\ 
http POST http://mockbin.com/request?foo=bar&foo=baz \
accept:application/json \
content-type:application/json \
cookie:foo=bar; bar=baz

After:

echo'{"foo": "bar"}'|\ # Improved readability
http POST 'http://mockbin.com/request?foo=bar&foo=baz'\ # Quoted "&"
accept:application/json \ # No quoting necessary
content-type:application/json \ # No quoting necessary
cookie:'foo=bar; bar=baz'# Quoted ";"

The cURL command (and possible also Wget) most likely suffer from improper quoting as well. It's not completely missing, as was the case of HTTPie, but it uses double quotes so literals like "foo bar $HOME baz" might get expanded by the shell. I think the same quoting mechanism should be used there as well.

 Before, the resultant shell command was completely unquoted. This change
introduces proper quoting of values and the URL - when necessary.
It uses single quotes which provide "strong quoting" (only nested single quote
characters need to be taken care of) and also make the output more
readable as double quotes, ubiquitous in JSON, don't require escaping.
Before:
echo "{\"foo\": \"bar\"}" | \
http POST http://mockbin.com/request?foo=bar&foo=baz \
accept:application/json \
content-type:application/json \
cookie:foo=bar; bar=baz
After:
echo '{"foo": "bar"}' | \
http POST 'http://mockbin.com/request?foo=bar&foo=baz' \
accept:application/json \
content-type:application/json \
cookie:'foo=bar; bar=baz'
@thibaultcha

Copy link
Copy Markdown
Member

👍

@ahmadnassri

Copy link
Copy Markdown

nice 👍 thanks @jakubroztocil I will integrate this with curl and wget as well.

@ahmadnassriahmadnassri self-assigned this Mar 13, 2015
ahmadnassri added a commit that referenced this pull request Mar 17, 2015
Use proper quoting in HTTPie shell commands
@ahmadnassri
ahmadnassri merged commit afecfd4 into Kong:masterMar 17, 2015
Sign up for freeto 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.

3 participants

@jkbrzt@thibaultcha@ahmadnassri