Opened 4 years ago

Closed 4 years ago

Last modified 4 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)

Hi,

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 (https://docs.python.org/3/library/html.parser.html) 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, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 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, 4 years ago

Easy pickings: set

comment:4 by Hasan Ramezani, 4 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, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 4 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@…>, 4 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