This makes it hard to write tests when testing XSS vulnerabilities in our
tags and filters. Though the assertions work correct, the error messages
don't show the correct differences.
**Steps to reproduce**
{{{
from django.test import TestCase
class UtilsTestCase(TestCase):
def test_assersion(self):
escaped = "<p><foo></p>"
raw = "<p><foo></p>"
self.assertHTMLEqual(escaped, raw)
}}}
**Expected Output**
{{{
AssertionError: <p>
<foo>
</p> != <p>
<foo>
</p>
<p>
- <foo>
+ <foo>
</p>
}}}
**Actual Output**
{{{
AssertionError: <p>
<foo>
</p> != <p>
<foo>
</p>
<p>
<foo>
</p>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33236>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Pratyush Mittal):
The bug is probably caused because the `__str__` method in the `Element`
class treats all its children the same. The children are either a tree or
string. In the case of a string, the Python's HTMLParser unescapes the
contents. For their string representation, we probably need to escape them
back.
I have tried to fix this in this pull-request:
https://github.com/django/django/pull/15033
--
Ticket URL: <https://code.djangoproject.com/ticket/33236#comment:1>
* owner: nobody => Pratyush Mittal
* needs_better_patch: 0 => 1
* status: new => assigned
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33236#comment:2>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33236#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"f38458fe56bf8850da72a924bd2e8ff59c6adf06" f38458fe]:
{{{
#!CommitTicketReference repository=""
revision="f38458fe56bf8850da72a924bd2e8ff59c6adf06"
Fixed #33236 -- Fixed assertHTMLEqual() error messages for escaped HTML.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33236#comment:4>