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?
--
Ticket URL: <https://code.djangoproject.com/ticket/32547>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> 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?
New description:
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?
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:1>
* type: Uncategorized => Cleanup/optimization
* component: Testing framework => Documentation
* stage: Unreviewed => Accepted
Comment:
Agreed, we should clarify this in
[https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.SimpleTestCase.assertHTMLEqual
assertHTMLEqual()],
[https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.SimpleTestCase.assertHTMLNotEqual
assertHTMLNotEqual()] docs and
[https://github.com/django/django/blob/876dc0c1a7dbf569782eb64f62f339c1daeb75e0/django/test/html.py#L227-L232
parse_html()] docstring.
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:2>
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:3>
* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1
Comment:
I've created a [https://github.com/django/django/pull/14143 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"ceb4b9ee68dffc6ab0398886f1758f15f037c472" ceb4b9e]:
{{{
#!CommitTicketReference repository=""
revision="ceb4b9ee68dffc6ab0398886f1758f15f037c472"
Fixed #32547 -- Corrected notes about validation in HTML assertions docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"6b020f3c94fb7f27875d5fe21a71a5ee7c9a7538" 6b020f3c]:
{{{
#!CommitTicketReference repository=""
revision="6b020f3c94fb7f27875d5fe21a71a5ee7c9a7538"
[3.2.x] Fixed #32547 -- Corrected notes about validation in HTML
assertions docs.
Backport of ceb4b9ee68dffc6ab0398886f1758f15f037c472 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32547#comment:7>