backslashes that precede a number are not preserved
See original GitHub issueChecklist
- I’ve searched for similar issues.
- I’m using the latest version of HTTPie.
Minimal reproduction code and steps
$ http --offline --print=B : \\0=
Current result
{
"0": ""
}
Expected result
{
"\\0": ""
}
Debug output
Please re-run the command with --debug
, then copy the entire command & output and paste both below:
$ http --debug --offline --print=B : \\0=
HTTPie 3.2.1
Requests 2.22.0
Pygments 2.7.2
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0]
/usr/bin/python3
Linux 5.10.102.1-microsoft-standard-WSL2
<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x7f494214a5e0>,
'args': Namespace(),
'as_silent': <function Environment.as_silent at 0x7f494214a4c0>,
'colors': 256,
'config': {'default_options': []},
'config_dir': PosixPath('/home/ducaale/.httpie'),
'devnull': <property object at 0x7f494212a310>,
'is_windows': False,
'log_error': <function Environment.log_error at 0x7f494214a550>,
'program_name': 'http',
'quiet': 0,
'rich_console': <functools.cached_property object at 0x7f49421c37f0>,
'rich_error_console': <functools.cached_property object at 0x7f4942122910>,
'show_displays': True,
'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
'stderr_isatty': True,
'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
'stdin_encoding': 'utf-8',
'stdin_isatty': True,
'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
'stdout_encoding': 'utf-8',
'stdout_isatty': True}>
<PluginManager {'adapters': [],
'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
<class 'httpie.plugins.builtin.DigestAuthPlugin'>,
<class 'httpie.plugins.builtin.BearerAuthPlugin'>],
'converters': [],
'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
<class 'httpie.output.formatters.json.JSONFormatter'>,
<class 'httpie.output.formatters.xml.XMLFormatter'>,
<class 'httpie.output.formatters.colors.ColorFormatter'>]}>
>>> requests.request(**{'auth': None,
'data': b'{"0": ""}',
'headers': <HTTPHeadersDict('User-Agent': b'HTTPie/3.2.1', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json')>,
'method': 'post',
'params': <generator object MultiValueOrderedDict.items at 0x7f4941d267b0>,
'url': 'http://localhost'})
{
"0": ""
}
Additional information, screenshots, or code examples
N/A
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Why do numbers in a string become "x0n" when a backslash ...
To keep non-printable characters from either causing havoc or not be shown at all, Python uses the same escape sequence syntax to represent...
Read more >shell - Read a variable with "read" and preserve backslashes ...
The problem is that read treats backslash in its input as an escape operator (to escape the separators when using read word1 word2...
Read more >3.3. Quoting characters
A non-quoted backslash, \, is used as an escape character in Bash. It preserves the literal value of the next character that follows,...
Read more >What's up with the strange treatment of quotation marks and ...
An odd number of backslashes followed by a quotation mark is treated as pairs of protected backslashes, followed by a protected quotation mark....
Read more >20.2. Dealing with Escape Sequences (\) - InformIT
C++ assigns special meaning to the backslash within a string literal and requires it to be escaped to be read as an actual...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PowerShell doesn’t treat backslashes specially so you’re actually handing HTTPie two backslashes instead of one. It’s clearer if we use single quotes. Bash:
PowerShell:
Not mentioned in the OP is that this used to work differently:
Yes, it’s a bug. It looks like the nested JSON array notation is getting in the way. Here’s a minimal reproduction: