Skip to content

Commit

Permalink
fix: handle empty style tag (#25910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 11, 2024
1 parent f6d0039 commit b47d9d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions frappe/tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def test_read_options_from_html(self):
# 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})
Expand Down
4 changes: 2 additions & 2 deletions frappe/utils/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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 = [
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b47d9d5

Please sign in to comment.