Skip to content

Commit

Permalink
Don’t crash with empty list marker strings
Browse files Browse the repository at this point in the history
Fix #1883.
  • Loading branch information
liZe committed Aug 10, 2024
1 parent 9213f62 commit 1b8ac91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/css/test_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ def test_list_style_types(style_type, values):
assert li_4.children[0].children[0].children[0].text == values[3]


def test_list_style_type_empty_string():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1883
render_pages('<ul><li style="list-style-type: \'\'">')


def test_counter_set():
page, = render_pages('''
<style>
Expand Down
9 changes: 4 additions & 5 deletions weasyprint/formatting_structure/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,10 @@ def marker_to_box(element, state, parent_style, style_for, get_image_from_uri,
counter_value = counter_values.get('list-item', [0])[-1]
counter_type = style['list_style_type']
# TODO: rtl numbered list has the dot on the left
marker_text = counter_style.render_marker(
counter_type, counter_value)
box = boxes.TextBox.anonymous_from(box, marker_text)
box.style['white_space'] = 'pre-wrap'
children.append(box)
if marker_text := counter_style.render_marker(counter_type, counter_value):
box = boxes.TextBox.anonymous_from(box, marker_text)
box.style['white_space'] = 'pre-wrap'
children.append(box)

if not children:
return
Expand Down

0 comments on commit 1b8ac91

Please sign in to comment.