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

converting HTML to PDF failed if no data type provided in img tag #35

Closed
grigoriev opened this issue Jul 22, 2024 · 0 comments · Fixed by #36 or #37
Closed

converting HTML to PDF failed if no data type provided in img tag #35

grigoriev opened this issue Jul 22, 2024 · 0 comments · Fixed by #36 or #37
Assignees
Labels
bug Something isn't working

Comments

@grigoriev
Copy link
Contributor

Current Behavior

provided html contains the following tag

<img title="name.jpeg" src="data:null;base64, /9j/....

processing crashed:

2024-07-22 15:24:47 ::ffff:192.168.65.1 - - [2024-07-22 13:24:47] "POST /convert/html?presentational_hints=true&pdf_variant=pdf%2Fa-2b HTTP/1.1" 200 2977 0.021722
2024-07-22 15:28:16 ERROR:root:'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
2024-07-22 15:28:16 Traceback (most recent call last):
2024-07-22 15:28:16   File "/opt/weasyprint/app/WeasyprintController.py", line 35, in convert_html
2024-07-22 15:28:16     html = SvgUtils.process_svg(html)
2024-07-22 15:28:16            ^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-22 15:28:16   File "/opt/weasyprint/app/SvgUtils.py", line 15, in process_svg
2024-07-22 15:28:16     return re.sub(pattern, replace_img_base64, html)
2024-07-22 15:28:16            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-22 15:28:16   File "/usr/local/lib/python3.12/re/__init__.py", line 186, in sub
2024-07-22 15:28:16     return _compile(pattern, flags).sub(repl, string, count)
2024-07-22 15:28:16            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-22 15:28:16   File "/opt/weasyprint/app/SvgUtils.py", line 26, in replace_img_base64
2024-07-22 15:28:16     replaced_content_base64 = replace_svg_with_png(content_base64)
2024-07-22 15:28:16                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-22 15:28:16   File "/opt/weasyprint/app/SvgUtils.py", line 36, in replace_svg_with_png
2024-07-22 15:28:16     svg_content = base64.b64decode(possible_svg_base64_content).decode('utf-8')
2024-07-22 15:28:16                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-22 15:28:16 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
2024-07-22 15:28:16 ::ffff:192.168.65.1 - - [2024-07-22 13:28:16] "POST /convert/html?presentational_hints=true&pdf_variant=pdf%2Fa-2b HTTP/1.1" 400 215 0.008822

Expected Behavior

image will not be replaced

Steps To Reproduce

see current behavior section

Anything else

No response

@grigoriev grigoriev added the bug Something isn't working label Jul 22, 2024
@grigoriev grigoriev self-assigned this Jul 22, 2024
grigoriev added a commit that referenced this issue Jul 22, 2024
binary content can not be SVG

Refs: #35
@grigoriev grigoriev linked a pull request Jul 22, 2024 that will close this issue
4 tasks
@Jumas Jumas closed this as completed in #36 Jul 22, 2024
Jumas pushed a commit that referenced this issue Jul 22, 2024
binary content can not be SVG

Refs: #35
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
1 participant