fix: handle empty style tag (#25910)

This commit is contained in:
Ankush Menat 2024-04-11 15:36:36 +05:30 committed by GitHub
parent f6d003963c
commit b47d9d57fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View file

@ -63,6 +63,13 @@ class TestPdf(FrappeTestCase):
# so it should not be extracted into options
self.assertFalse(options.get("margin-right"))
def test_empty_style(self):
html = """<style></style>
<div class="more-info">Hello</div>
"""
_, options = pdfgen.read_options_from_html(html)
self.assertTrue(options)
def test_pdf_encryption(self):
password = "qwe"
pdf = pdfgen.get_pdf(self.html, options={"password": password})

View file

@ -17,7 +17,7 @@ from pypdf import PdfReader, PdfWriter
import frappe
from frappe import _
from frappe.core.doctype.file.utils import find_file_by_url
from frappe.utils import scrub_urls
from frappe.utils import cstr, scrub_urls
from frappe.utils.jinja_globals import bundled_asset, is_rtl
PDF_CONTENT_ERRORS = [
@ -242,7 +242,7 @@ def get_print_format_styles(soup: BeautifulSoup) -> list[cssutils.css.Property]:
# Prepare a css stylesheet from all the style tags' contents
for style_tag in style_tags:
stylesheet += style_tag.string
stylesheet += cstr(style_tag.string)
# Use css parser to tokenize the classes and their styles
parsed_sheet = cssutils.parseString(stylesheet)