From 63eae7ea322863a3a90268e0868589c60278ebd9 Mon Sep 17 00:00:00 2001 From: coderabhishek Date: Tue, 8 Mar 2016 00:19:05 +0530 Subject: [PATCH] std.xml: accept single quotes for attributes Fixes issue 4509 - XML parser in std.xml throws TagException if the attr value is put in apostrophes. --- std/xml.d | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/std/xml.d b/std/xml.d index 3b3626eef18..c7a0ff375d5 100644 --- a/std/xml.d +++ b/std/xml.d @@ -1059,9 +1059,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; } @@ -2712,6 +2713,16 @@ EOS"; } } +unittest +{ + string test_xml = ``; + + DocumentParser parser = new DocumentParser(test_xml); +} + unittest { string s = q"EOS @@ -2858,6 +2869,15 @@ private s = s[1..$]; } + char requireOneOf(ref string s, string chars) + { + 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; @@ -2970,3 +2990,5 @@ private throw new XMLException(s); } } + +