Opened 4 years ago

Closed 4 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: master
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 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted
Version: 1.8master

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

comment:2 Changed 4 years ago by Kamil Warguła

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

comment:3 Changed 4 years ago by Mihai Iachimovschi

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 Changed 4 years ago by Kamil Warguła

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 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:7 Changed 4 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

comment:8 Changed 4 years ago by Jacek Bzdak

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 Changed 4 years ago by Mattia Larentis

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 Changed 4 years ago by Mattia Larentis

Patch needs improvement: unset

comment:11 Changed 4 years ago by Simon Charette

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 Changed 4 years ago by Tim Graham <timograham@…>

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