diff --git a/std/xml.d b/std/xml.d index 2806ccd3222..943d47a0db3 100644 --- a/std/xml.d +++ b/std/xml.d @@ -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; } @@ -2722,6 +2723,26 @@ EOS"; } } +@system unittest +{ + string test_xml = ` + `; + + 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 @@ -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;