question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

backslashes that precede a number are not preserved

See original GitHub issue

Checklist

  • 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:open
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
blyxxyzcommented, Jun 7, 2022

Probably because of your shell. It works fine for me on PowerShell

> http --offline --print=B : \\0=
{
    "\\0": ""
}

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:

$ http --offline --print=B : '\0='
{
    "0": ""
}


$ http --offline --print=B : '\\0='
{
    "\\0": ""
}

PowerShell:

PS > http.exe --offline --print=B : '\0='
{
    "0": ""
}


PS > http.exe --offline --print=B : '\\0='
{
    "\\0": ""
}

Not mentioned in the OP is that this used to work differently:

$ git checkout 2.0.0
HEAD is now at a7e5228 Cleanup
$ python3 -m httpie --offline --print=B : '\0='
{
    "\\0": ""
}
0reactions
jakubroztocilcommented, Jun 7, 2022

Yes, it’s a bug. It looks like the nested JSON array notation is getting in the way. Here’s a minimal reproduction:

$ http --offline pie.dev/post '\0=\0'
{
    "0": "\\0"
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found