-
-
Notifications
You must be signed in to change notification settings - Fork 159
Ensure bytestring is bytes before checking for gzip header #443
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
Ensure bytestring is bytes before checking for gzip header #443
Conversation
Related error: TypeError: startswith first arg must be str or a tuple of str, not bytes
|
Hi! This is probably already fixed in 2.8.1, did you try the latest version? |
Yes, I tested it with the latest version (2.8.1), and the issue still occurs. |
Could you please share a code sample that shows your problem? |
|
I was able to reproduce it with this small example import sys
import cairosvg
print(f"Python version: {sys.version}")
print(f"CairoSVG version: {cairosvg.__version__}")
svg_str = (
"<svg width='100' height='100'><rect width='100' height='100'/></svg>"
)
cairosvg.svg2png(bytestring=svg_str)Output: Python version: 3.11.9 (main, Apr 10 2024, 13:16:36) [GCC 13.2.0]
CairoSVG version: 2.8.1
Traceback (most recent call last):
File "test.py", line 12, in <module>
cairosvg.svg2png(bytestring=svg_str)
File "/home/metal/.virtualenvs/thumbor/lib/python3.11/site-packages/cairosvg/__init__.py", line 54, in svg2png
return surface.PNGSurface.convert(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/metal/.virtualenvs/thumbor/lib/python3.11/site-packages/cairosvg/surface.py", line 129, in convert
tree = Tree(
^^^^^
File "/home/metal/.virtualenvs/thumbor/lib/python3.11/site-packages/cairosvg/parser.py", line 390, in __init__
if bytestring.startswith(b'\x1f\x8b'):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: startswith first arg must be str or a tuple of str, not bytes |
Thanks. The Let’s fix that to avoid breaking other libraries! |
|
Thank you @liZe ! On my side, I’ll make sure to fix it so that it only passes bytes — not Unicode strings. Thanks again! |
More info at: Kozea/CairoSVG#443
More info at: Kozea/CairoSVG#443
More info at: Kozea/CairoSVG#443
Fixes a TypeError when checking if input is gzipped using
bytestring.startswith(b"\x1f\x8b").This patch ensures
bytestringis properly encoded asbytesbefore gzip header detection.