Skip to content

Commit

Permalink
Merge pull request #4567 from aG0aep6G/4509
Browse files Browse the repository at this point in the history
Fix issue 4509 - XML parser in std.xml throws TagException if the attr value is put in apostrophes.
  • Loading branch information
H. S. Teoh committed Jul 6, 2016
2 parents 0641a8d + bab9832 commit d231d78
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions std/xml.d
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

0 comments on commit d231d78

Please sign in to comment.