Bug 3200 – std.xml doesn't follow spec for Tag.text
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-07-21T18:01:00Z
Last change time
2015-06-09T01:28:08Z
Keywords
patch
Assigned to
rsinfu
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2009-07-21T18:01:42Z
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 & Up">What & 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();
}
Comment #1 by r.sagitario — 2010-04-05T09:44:15Z
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);