Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions std/xml.d
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,10 @@ class Tag
munch(s,whitespace);
reqc(s,'=');
munch(s,whitespace);
reqc(s,'"');
string val = decode(munch(s,"^\""), DecodeMode.LOOSE);
reqc(s,'"');
char quote = requireOneOf(s,"'\"");
char[2] notQuote = ['^', quote];
string val = decode(munch(s,notQuote[]), DecodeMode.LOOSE);
reqc(s,quote);
munch(s,whitespace);
attr[key] = val;
}
Expand Down Expand Up @@ -2722,6 +2723,26 @@ EOS";
}
}

@system unittest
{
string test_xml = `<?xml version="1.0" encoding='UTF-8'?><r><stream:stream
xmlns:stream="http://etherx.'jabber'.org/streams"
xmlns="jabber:'client'" from='jid.pl' id="587a5767"
xml:lang="en" version="1.0" attr='a"b"c'>
</stream:stream></r>`;

DocumentParser parser = new DocumentParser(test_xml);
bool tested = false;
parser.onStartTag["stream:stream"] = (ElementParser p) {
assert(p.tag.attr["xmlns"] == "jabber:'client'");
assert(p.tag.attr["from"] == "jid.pl");
assert(p.tag.attr["attr"] == "a\"b\"c");
tested = true;
};
parser.parse();
assert(tested);
}

@system unittest
{
string s = q"EOS
Expand Down Expand Up @@ -2868,6 +2889,15 @@ private
s = s[1..$];
}

char requireOneOf(ref string s, string chars) @safe
{
if (s.length == 0 || indexOf(chars,s[0]) == -1)
throw new TagException("");
char ch = s[0];
s = s[1..$];
return ch;
}

size_t hash(string s,size_t h=0) @trusted nothrow
{
return typeid(s).getHash(&s) + h;
Expand Down