Bug 4069 – std.xml.Document.pretty saves empty elements with spaces and line breaks

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-04-05T10:11:00Z
Last change time
2014-02-14T20:35:17Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2010-04-05T10:11:32Z
Test case: import std.stdio; import std.xml; import std.string; void main() { auto doc = new Document(new Tag("root")); doc ~= new Element("elem", ""); string s = join(doc.pretty(1),""); writefln("doc: '%s'", s); auto xml = new Document(s); string t = xml.elements[0].text(); writefln("elem: '%s'", t); assert(t == ""); } outputs: doc: '<root> <elem> </elem></root>' elem: ' ' core.exception.AssertError@test(17): Assertion failure This does not happen with non-empty elements or with Document.toString
Comment #1 by r.sagitario — 2010-04-05T10:13:53Z
Here's a patch that switches to the short form of an empty element: Index: xml.d =================================================================== --- xml.d (revision 1476) +++ xml.d (working copy) @@ -887,7 +887,7 @@ return buffer; } - override bool isEmptyXML() { return false; } /// Returns false always + override bool isEmptyXML() { return items.length == 0; } } } The resulting output is: doc: '<root> <elem /></root>' elem: ''
Comment #2 by bugzilla — 2011-02-07T00:45:13Z