diff --git a/frappe/tests/test_pdf.py b/frappe/tests/test_pdf.py index 4ae8e8ff3c8..243cd0f7b24 100644 --- a/frappe/tests/test_pdf.py +++ b/frappe/tests/test_pdf.py @@ -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 = """ +
Hello
+ """ + _, 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}) diff --git a/frappe/utils/pdf.py b/frappe/utils/pdf.py index 7325f872013..a5de5808b9b 100644 --- a/frappe/utils/pdf.py +++ b/frappe/utils/pdf.py @@ -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 = [ @@ -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)