www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3200] New: std.xml doesn't follow spec for Tag.text

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

           Summary: std.xml doesn't follow spec for Tag.text
           Product: D
           Version: 2.031
          Platform: Other
               URL: http://digitalmars.com/d/2.0/phobos/std_xml.html#text
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com


According to the documentation having & in a tag will be turned to &. The
example code below will output:

Attr: What & Up
Elem: What & Up

*testfile.xml:*

<?xml version="1.0" encoding="utf-8"?> <Tests>
    <Test thing="What &amp; Up">What &amp; Up</Test>
</Tests>


*test.d:*

import std.stdio;
import std.xml;

void main() {
    auto file = "testfile.xml";

    auto s = cast(string)std.file.read(file);

    auto xml = new DocumentParser(s);

    xml.onStartTag["Test"] = (ElementParser xml) {
        writeln("Attr: ", xml.tag.attr["thing"]);
    };

    xml.onEndTag["Test"] = (in Element e) {
        writeln("Elem: ", e.text);
    };
    xml.parse();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3200


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |r.sagitario gmx.de


--- Comment #1 from Rainer Schuetze <r.sagitario gmx.de> 2010-04-05 09:44:15
PDT ---
This is caused by encode and decode being inverted for attributes and the the
element text never being decoded. Here is a patch

Index: xml.d
===================================================================
--- xml.d    (revision 1476)
+++ xml.d    (working copy)
   -991,7 +991,7   
                 reqc(s,'=');
                 munch(s,whitespace);
                 reqc(s,'"');
-                string val = encode(munch(s,"^\""));
+                string val = decode(munch(s,"^\""));
                 reqc(s,'"');
                 munch(s,whitespace);
                 attr[key] = val;
   -1088,7 +1088,7   
             {
                 string s = "<" ~ name;
                 foreach(key,val;attr)
-                    s ~= format("
%s=\"%s\"",key,decode(val,DecodeMode.LOOSE));
+                    s ~= format(" %s=\"%s\"",key,encode(val.dup)); //
decode(val,DecodeMode.LOOSE));
                 return s;
             }

   -1945,7 +1945,7   
                     invariant(char)* p = startTag.tagString.ptr
                         + startTag.tagString.length;
                     invariant(char)* q = tag_.tagString.ptr;
-                    text = p[0..(q-p)];
+                    text = decode(p[0..(q-p)]);

                     auto element = new Element(startTag);
                     if (text.length != 0) element ~= new Text(text);

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


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |rsinfu gmail.com
         AssignedTo|nobody puremagic.com        |rsinfu gmail.com


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


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from Shin Fujishiro <rsinfu gmail.com> 2010-05-23 04:57:04 PDT
---
Fixed in svn r1544.
Thanks for the patch!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 23 2010