www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4069] New: std.xml.Document.pretty saves empty elements with spaces and line breaks

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4069

           Summary: std.xml.Document.pretty saves empty elements with
                    spaces and line breaks
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: r.sagitario gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-05 10:11:32
PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4069


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, wrong-code


--- Comment #1 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-05 10:13:53
PDT ---
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: ''

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 05 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4069


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2011-02-07
00:45:13 PST ---
https://github.com/D-Programming-Language/phobos/commit/b3ad939cf41adfefd33b16d2d91ca56d568cddac

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2011