Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape text content in cli #2050

Closed
tomchristie opened this issue Jan 27, 2022 · 1 comment
Closed

Escape text content in cli #2050

tomchristie opened this issue Jan 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@tomchristie
Copy link
Member

There's some cases where our console output can raise exceptions, because we're not currently escaping anything that might be interpreted by rich as a markup template tag.

Will has already done a little work on this here #1866 but I expect that it needs updating, and probably isn't complete.

Eg...

$ httpx https://cataas.com/cat 
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Thu, 27 Jan 2022 11:19:17 GMT
Content-Type: image/jpeg
Content-Length: 40849
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Cache-Control: public, max-age=30
ETag: 1643256053593

Traceback (most recent call last):
  File "venv/bin/httpx", line 11, in <module>
    load_entry_point('httpx', 'console_scripts', 'httpx')()
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 486, in main
    print_response(response)
  File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 176, in print_response
    console.print(response.text)
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1602, in print
    highlight=highlight,
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1460, in _collect_renderables
    renderable, emoji=emoji, markup=markup, highlighter=_highlighter
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1355, in render_str
    emoji_variant=self._emoji_variant,
  File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/markup.py", line 161, in render
    ) from None
rich.errors.MarkupError: closing tag '[/�$B����c}Nʌ��W�a�����}O��W��4Q;!�����0]' at position 3761 doesn't match any open tag

(Note that the above URL happens to return a random cat image, so you'll only sometimes see this error.)

@tomchristie tomchristie added the bug Something isn't working label Jan 27, 2022
@tomchristie
Copy link
Member Author

Resolved in #1866 (I added one additional escape in there)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant