Opened 9 years ago

Closed 8 years ago

#25170 closed Bug (fixed)

assertXMLEqual fails when white space is present outside XML fragment

Reported by: Sergiy Kuzmenko Owned by: Kamil Warguła
Component: Testing framework Version: dev
Severity: Normal Keywords: test
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

Currently this test fails:

class MyTestCase(TestCase):
    def test_xml(self):
        self.assertXMLEqual('<greeting>hello</greeting>', '<greeting>hello</greeting>\n')

I believe this is a bug because white space outside root tag should not matter. It makes testing rather confusing when reading XML documents from files (which may or may not have trailing new line characters).

Change History (12)

comment:1 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted
Version: 1.8master

Seems reasonable as the docstring says "Whitespace in most cases is ignored".

comment:2 by Kamil Warguła, 9 years ago

Owner: changed from nobody to Kamil Warguła
Status: newassigned

comment:3 by Mihai Iachimovschi, 9 years ago

At the time of analyzing the issue, I didn't notice that the issue is already assigned. Anyway, just because the fix seems so simple, and there is no pull request yet, I published my own solution as a PR.

The fixed branch is available here: https://github.com/mishunika/django/tree/ticket_25170
And the PR is here: https://github.com/django/django/pull/5049

comment:4 by Kamil Warguła, 9 years ago

I started working on this bug after assigned.
This is PR for this issue: https://github.com/django/django/pull/5052
Resolution of this bug is different then @mishunika.

comment:5 by Tim Graham, 9 years ago

Has patch: set

I think PR 5052 is more correct in that it will continue to consider whitespace *inside* a tag significant; e.g. the following snippets shouldn't be considered equal:

<tag>foo </tag>
<tag>foo</tag>

Anyone to confirm that? The author of PR 5049 argues otherwise.

comment:6 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Tim Graham, 9 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 by Jacek Bzdak, 8 years ago

Whitespace around tags is indeed siginificant --- technically following documents *are* different

<foo></foo>

and

<foo> 
</foo>

however for most practical purposes this difference is insignificant, as most of XML-based formats ignore whitespace altogether (like html). Despite that I think that in unittesting framework we should rather assume pessimistic case that whitespace does matter.

comment:9 by Mattia Larentis, 8 years ago

According to https://tools.ietf.org/html/rfc3470#section-4.16

In XML instances all white space is considered significant and is by default visible to processing applications

So, I think that @jbzdak is right.

comment:10 by Mattia Larentis, 8 years ago

Patch needs improvement: unset

comment:11 by Simon Charette, 8 years ago

Triage Stage: AcceptedReady for checkin

Contained white-space should really be considered significant in the HTML case.

If I remember correctly it affect display: inline elements in some way (or it did in the past).

Stripping leading and trailing white space makes sense to me.

comment:12 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 2085d8d5:

Fixed #25170 -- Made assertXMLEqual()/assertXMLNotEqual() ignore leading and trailing whitespace.

Thanks Jacek Bzdak for indepdently contributing a similar fix.

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