Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32547 closed Cleanup/optimization (fixed)

assertHTMLEqual()/assertHTMLNotEqual() allow invalid HTML.

Reported by: François Poulain Owned by: Hasan Ramezani
Component: Documentation Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by François Poulain)


The docs for assertHTMLEqual says "html1 and html2 must be valid HTML.". The formulation suggest that html validation is enforced. But is is actually easy to get test succeeding with invalid html. Eg.

SimpleTestCase.assertHTMLEqual(None, '<div class="bling" class="blang">', '<div class="bling" class="blang">')

The code rely on Python's HTMLParser ( for which the documentation states it produce parsers "able to parse invalid markup.".

I suggest to correct documentation and/or to enforce validation on the parser side.

How do you think about it?

Change History (7)

comment:1 by François Poulain, 3 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 3 years ago

Component: Testing frameworkDocumentation
Summary: assertHTMLEqual allows invalid HTMLassertHTMLEqual()/assertHTMLNotEqual() allow invalid HTML.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Agreed, we should clarify this in assertHTMLEqual(), assertHTMLNotEqual() docs and parse_html() docstring.

comment:3 by Mariusz Felisiak, 3 years ago

Easy pickings: set

comment:4 by Hasan Ramezani, 3 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

I've created a PR and removed the must be valid HTML and An AssertionError will be raised if one of them cannot be parsed. from
assertHTMLEqual() and ​assertHTMLNotEqual() docs.

comment:5 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In ceb4b9e:

Fixed #32547 -- Corrected notes about validation in HTML assertions docs.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 6b020f3c:

[3.2.x] Fixed #32547 -- Corrected notes about validation in HTML assertions docs.

Backport of ceb4b9ee68dffc6ab0398886f1758f15f037c472 from main

Note: See TracTickets for help on using tickets.
Back to Top