Skip to content

Use ANSI-C quoting for curl and httpie export bodies with control characters - #8426

Open
monasco wants to merge 2 commits into
mitmproxy:mainfrom
monasco:fix-curl-export-quoting
Open

monasco wants to merge 2 commits into
mitmproxy:mainfrom
monasco:fix-curl-export-quoting

Conversation

@monasco

@monasco monasco commented Sep 7, 2026

Copy link
Copy Markdown

Description

The curl and httpie export passed bodies with control characters as "$(printf '...')". printf treats % and backslash sequences as format directives, and $(...) strips newlines at the end. So a body like {"a":1} plus newline was sent without the newline, and a=100% plus newline was cut to a=100.

The body is now quoted with ANSI-C quoting ($'...'). Backslashes and single quotes are escaped, control characters become \xNN. I ran the exported commands in bash and zsh against a local server, the bodies arrive byte for byte.

Bodies without control characters still use shlex.quote, nothing changes for them.

Fixes #8425

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

This branch has not been deployed

No deployments
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.

curl and httpie export change the body when it has % or a trailing newline

1 participant