Skip to content

Test failures with lxml 5.4.0 #24

Closed

Description

@mweinelt

After upgrading to lxml 5.4.0 we are seeing the following tests regressing on nixpkgs.

======================================================================
FAIL: test_host_whitelist_invalid (tests.test_clean.CleanerTest.test_host_whitelist_invalid)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/source/tests/test_clean.py", line 343, in test_host_whitelist_invalid
    self.assertEqual(expected, cleaner.clean_html(html))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '<div></div>' != '<div>&lt;/div&gt;</div>'
- <div></div>
+ <div>&lt;/div&gt;</div>


======================================================================
FAIL: test_host_whitelist_sneaky_userinfo (tests.test_clean.CleanerTest.test_host_whitelist_sneaky_userinfo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/source/tests/test_clean.py", line 350, in test_host_whitelist_sneaky_userinfo
    self.assertEqual(expected, cleaner.clean_html(html))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '<div></div>' != '<div>&lt;/div&gt;</div>'
- <div></div>
+ <div>&lt;/div&gt;</div>


======================================================================
FAIL: test_host_whitelist_valid (tests.test_clean.CleanerTest.test_host_whitelist_valid)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/source/tests/test_clean.py", line 337, in test_host_whitelist_valid
    self.assertEqual(expected, cleaner.clean_html(html))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '<div><iframe src="https://example.com/page"></iframe></div>' != '<div><iframe src="https://example.com/page">&lt;/div&gt;</iframe></div>'
- <div><iframe src="https://example.com/page"></iframe></div>
+ <div><iframe src="https://example.com/page">&lt;/div&gt;</iframe></div>
?                                             ++++++++++++


----------------------------------------------------------------------
Ran 28 tests in 0.019s

FAILED (failures=3, skipped=1)

Activity

  1. frenzymadness commented on Jun 18, 2025

    @frenzymadness
    Member

    Thank you for the report. So far, I'm not able to reproduce the issue. When I build the latest version of lxml_html_clean in Fedora rawhide with lxml 5.4.0, it works fine and all tests pass. The same happens to me when I run tox -e py313 with lxml 5.4.0 installed from PyPI.

    Acconrding to the changelog of 5.4.0, they updated wheels with libxml2 and libxslt and it seems that libxml2 in Fedora is older (2.12.10) than what upstream uses currently (2.13.8). This might be potentially the cause.

  2. vcunat commented on Jun 18, 2025

    @vcunat

    In nixpkgs we get this with libxml2 2.14

  3. frenzymadness commented on Jun 18, 2025

    @frenzymadness
    Member
  4. frenzymadness commented on Sep 29, 2025

    @frenzymadness
    Member

    If I understand this problem correctly, the change happened on lxml/libxml2 level. With the following reproducer:

    from lxml.html import fromstring, etree
    
    html = '<div><iframe src="foo"></div>'
    parsed = fromstring(html)
    print(etree.tostring(parsed))

    The latest lxml (6.0.2) with vendored libxml2 2.14.6 prints out:

    b'<div><iframe src="foo">&lt;/div&gt;</iframe></div>'
    

    while the older one (5.3.2) with libxml2 2.12.10 prints out:

    b'<div><iframe src="foo"/></div>'
    

    Let me check #25 whether the updated tests still make sense.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions