Skip to content

Fixed #36499 -- Adjusted utils_tests.test_html.TestUtilsHtml.test_strip_tags following Python's HTMLParser new behavior. #19639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nessita
Copy link
Contributor

@nessita nessita commented Jul 14, 2025

🛑 Not to be merged before 3.13.6, 3.12.12, 3.11.14, 3.10.19 and 3.9.24 are released (and Jenkins CI gets updated).

Trac ticket number

ticket-36499

Branch description

As described in the ticket, Python's HTMLParser was adjusted to avoid poor performance on malformed HTML. This branch adjust the Django tests that were specifically added for performance related reports to follow Python's HTMLParser behavior.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.

@nessita nessita marked this pull request as draft July 14, 2025 17:53
@felixxm
Copy link
Member

felixxm commented Jul 15, 2025

There is one more failure in test_utils.tests.HTMLEqualTests.test_parsing_errors, it may be caused by the same change in HTMLParser.

@nessita
Copy link
Contributor Author

nessita commented Jul 15, 2025

There is one more failure in test_utils.tests.HTMLEqualTests.test_parsing_errors, it may be caused by the same change in HTMLParser.

Yeah, I started fixing this test yesterday, and I've been trying to think what the right fix is, because is not straightforward. Before, this line:

self.assertHTMLEqual("< div></ div>", "<div></div>")

would raise an AssertionError with message:

AssertionError: First argument is not valid HTML:
('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))

Now it fails with:

AssertionError: &lt; div&gt; != <div>
- &lt; div&gt;
+ <div>

I need to dig deeper to understand if the assertion message change is acceptable or not.

…ip_tags following Python's HTMLParser new behavior.
@nessita nessita requested a review from cliff688 July 16, 2025 14:41
Comment on lines -962 to +965
"('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))"
"('Unexpected end tag `div` (Line 1, Column 0)', (1, 0))"
)
with self.assertRaisesMessage(AssertionError, error_msg):
self.assertHTMLEqual("< div></ div>", "<div></div>")
self.assertHTMLEqual("</div>", "<div></div>")
Copy link
Member

@cliff688 cliff688 Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not about strip_tags(), I think the commit message needs to be adjusted to show this. Also, maybe it doesn't really matter, or may allow the changes here to be split into 2 commits, but the changes to HTMLParser resulting in this test failure are unrelated to those causing failures in strip_tags()'s tests.

Additionally, I think we can change to:

diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 494a0ea8d3..f2cfc55e2b 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -962,7 +962,7 @@ class HTMLEqualTests(SimpleTestCase):
             "('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))"
         )
         with self.assertRaisesMessage(AssertionError, error_msg):
-            self.assertHTMLEqual("< div></ div>", "<div></div>")
+            self.assertHTMLEqual("< div></div>", "<div></div>")
         with self.assertRaises(HTMLParseError):
             parse_html("</p>")

with the advantage of a (marginally 🌞) smaller diff and a test for a non-zero column position in the message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants