You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
curl and httpie export change the body when it has % or a trailing newline #8425
The curl and httpie export changes the request body when the body has a control character (for example a newline) together with %, a backslash, or a newline at the end. The exported command sends different bytes than the original request.
The body is passed as "$(printf '...')". printf treats % as a format directive and \n, \t and other backslash sequences as escapes. $(...) also removes newlines at the end of the output.
I ran the exported commands in bash against a local server and compared the bytes:
body in mitmproxy
exported
server received
{"a":1}\n
-d "$(printf '{"a":1}\x0a')"
{"a":1} (newline lost)
a=100%\nb=2
-d "$(printf 'a=100%\x0ab=2')"
a=100 and printf: '\': invalid format character
C:\new\temp\nx (two backslashes)
-d "$(printf 'C:\new\temp\x0ax')"
C:<LF>ew<TAB>emp<LF>x
A JSON body that ends with a newline is very common, so the first case happens a lot.
Steps to reproduce the behavior:
Capture a POST request whose body is {"a":1} followed by a newline.
Run export.clip curl @focus (or :export.clip curl @focus in the console) and paste the command into bash.
The server gets {"a":1} without the newline. With a body like a=100% followed by a newline the server gets only a=100.
Bodies without control characters are fine, they go through shlex.quote.
A fix is to use ANSI-C quoting ($'...') instead of printf. It expands \xNN byte for byte and does not touch %. I tested it in bash and zsh, all bodies above arrive unchanged. I will open a pull request.
Activity
wumingXZ commentedon Nov 18, 2026
The exported HTTPie command adds a line break to the end of the request body,which can make a signed request fail verification.