micha / resty

Little command line REST client that you can use in pipelines (bash or zsh).
MIT License
2.65k stars 143 forks source link

Query string not working for GET request #91

Open vapniks opened 3 years ago

vapniks commented 3 years ago

In zsh this works:

> curl 'https://qrng.anu.edu.au/API/jsonI.php?type=uint8&length=10'
{"type":"uint8","length":10,"data":[214,140,44,142,254,214,185,107,213,30],"success":true}

but this doesn't

> resty https://qrng.anu.edu.au/API
> GET /jsonI.php -q "type=uint8&length=10"
{"success":false}

It appears that resty quotes the ampersand:

> GET /jsonI.php -q "type=uint8&length=10" --dry-run
curl -sLv --data-binary '' -X GET -b "/home/me/.resty/c/qrng.anu.edu.au" -c "/home/me/.resty/c/qrng.anu.edu.au" "https://qrng.anu.edu.au/API/jsonI.php?type=uint8\&length=10"

am I doing something wrong?

silb commented 3 months ago

Looks like it was introduced in commit e9559924. The line for opt in "$@"; do all_opts+=($(printf '%q' "$opt")) ; done results in '&' between query parameters being escaped to '\&'

Example escape:

printf '%q' "p1=v1&p2=v2"

outputs 'p1=v1\&p2=v2'

edit: escape backslash in Markdown