Skip to content

Commit

Permalink
Merge pull request #956 from Tontyna/skip_crash
Browse files Browse the repository at this point in the history
Sanitize simplified line breaking
  • Loading branch information
liZe authored Nov 7, 2019
2 parents fc7e065 + 0fe6960 commit dbdc581
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
28 changes: 23 additions & 5 deletions weasyprint/layout/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,27 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
# add the original skip stack to the partial
# skip stack we get after the new rendering.

# We have to do:
# resume_at + initial_skip_stack
# but adding skip stacks is a bit complicated
current_skip_stack = initial_skip_stack
current_resume_at = (child_index, child_resume_at)
# Combining skip stacks is a bit complicated
# We have to:
# - set `child_index` as the first number
# - append the new stack if it's an absolute one
# - otherwise append the combined stacks
# (resume_at + initial_skip_stack)

# extract the initial index
if initial_skip_stack is None:
current_skip_stack = None
initial_index = 0
else:
initial_index, current_skip_stack = (
initial_skip_stack)
# child_resume_at is an absolute skip stack
if child_index > initial_index:
resume_at = (child_index, child_resume_at)
break

# combine the stacks
current_resume_at = child_resume_at
stack = []
while current_skip_stack and current_resume_at:
skip, current_skip_stack = (
Expand All @@ -875,6 +891,8 @@ def split_inline_box(context, box, position_x, max_x, skip_stack,
resume_at = current_resume_at
while stack:
resume_at = (stack.pop(), resume_at)
# insert the child index
resume_at = (child_index, resume_at)
break
if break_found:
break
Expand Down
53 changes: 53 additions & 0 deletions weasyprint/tests/test_layout/test_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,59 @@ def test_breaking_linebox_regression_10():
assert line4.children[0].text == ')x'


@assert_no_logs
def test_breaking_linebox_regression_11():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
'<style>@font-face {src: url(AHEM____.TTF); font-family: ahem}</style>'
'<p style="width:10em; font-family: ahem">'
' line 1<br><span>123 567 90</span>x'
'</p>')
html, = page.children
body, = html.children
p, = body.children
line1, line2, line3 = p.children
assert line1.children[0].text == 'line 1'
assert line2.children[0].children[0].text == '123 567'
assert line3.children[0].children[0].text == '90'
assert line3.children[1].text == 'x'


@assert_no_logs
def test_breaking_linebox_regression_12():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
'<style>@font-face {src: url(AHEM____.TTF); font-family: ahem}</style>'
'<p style="width:10em; font-family: ahem">'
' <br><span>123 567 90</span>x'
'</p>')
html, = page.children
body, = html.children
p, = body.children
line1, line2, line3 = p.children
assert line2.children[0].children[0].text == '123 567'
assert line3.children[0].children[0].text == '90'
assert line3.children[1].text == 'x'


@assert_no_logs
def test_breaking_linebox_regression_13():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
'<style>@font-face {src: url(AHEM____.TTF); font-family: ahem}</style>'
'<p style="width:10em; font-family: ahem">'
' 123 567 90 <span>123 567 90</span>x'
'</p>')
html, = page.children
body, = html.children
p, = body.children
line1, line2, line3 = p.children
assert line1.children[0].text == '123 567 90'
assert line2.children[0].children[0].text == '123 567'
assert line3.children[0].children[0].text == '90'
assert line3.children[1].text == 'x'


@assert_no_logs
def test_linebox_text():
page, = parse('''
Expand Down

0 comments on commit dbdc581

Please sign in to comment.