Skip to content

calc adding a percentage and an absolute value in object-position leads to an exception #2896

Description

@alexandergitter

The following example crashes WeasyPrint 69.0 with an exception:

<img style="object-position: calc(50% + 1px) 0;" src="https://picsum.photos/200">

It appears to be somehow related to the combination of the percentage + an absolute value. Here's the exception I get:

Traceback (most recent call last):
  File "/home/alex/src/WeasyPrint/weasyprint/css/__init__.py", line 1269, in __missing__
    raise Exception
Exception

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/alex/src/WeasyPrint/weasyprint/__main__.py", line 236, in <module>
    main()
  File "/home/alex/src/WeasyPrint/weasyprint/__main__.py", line 229, in main
    html.write_pdf(output, **options)
  File "/home/alex/src/WeasyPrint/weasyprint/__init__.py", line 269, in write_pdf
    return document.write_pdf(target, zoom, finisher, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/src/WeasyPrint/weasyprint/document.py", line 343, in write_pdf
    pdf = generate_pdf(self, target, zoom, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/src/WeasyPrint/weasyprint/pdf/__init__.py", line 223, in generate_pdf
    page.paint(stream, scale)
  File "/home/alex/src/WeasyPrint/weasyprint/document.py", line 87, in paint
    draw_page(self._page_box, stream)
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 29, in draw_page
    draw_stacking_context(stream, stacking_context)
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 123, in draw_stacking_context
    draw_stacking_context(stream, child_context)
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 123, in draw_stacking_context
    draw_stacking_context(stream, child_context)
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 118, in draw_stacking_context
    draw_block_level(
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 652, in draw_block_level
    draw_replacedbox(stream, block)
  File "/home/alex/src/WeasyPrint/weasyprint/draw/__init__.py", line 595, in draw_replacedbox
    draw_width, draw_height, draw_x, draw_y = replaced.replacedbox_layout(box)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/src/WeasyPrint/weasyprint/layout/replaced.py", line 89, in replacedbox_layout
    position = box.style['object_position']
               ~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/alex/src/WeasyPrint/weasyprint/css/__init__.py", line 1278, in __missing__
    function.source_line, function.source_column, function.serialize())
    ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'source_line'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashProblems preventing documents from being rendered

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions