From 9713d711bf15a65db55e77c5739f00ca8eebc399 Mon Sep 17 00:00:00 2001 From: anonymous Date: Thu, 15 Jun 2017 20:42:13 +0200 Subject: [PATCH 1/2] Revert "Removed level of indirection from internal std.xml.ElementParser code" This reverts commit 25fc16fa219d6e0e1bc48f3c422b3f10b3cd3a67. --- std/xml.d | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/std/xml.d b/std/xml.d index 1143dfa6d20..d55c6661857 100644 --- a/std/xml.d +++ b/std/xml.d @@ -564,7 +564,7 @@ class Document : Element this(xml.tag); prolog = s[0 .. tagString.ptr - s.ptr]; parse(xml); - epilog = xml.s; + epilog = *xml.s; } /** @@ -1721,7 +1721,7 @@ class DocumentParser : ElementParser body { xmlText = xmlText_; - s = xmlText; + s = &xmlText; super(); // Initialize everything parse(); // Parse through the root tag (but not beyond) } @@ -1748,7 +1748,7 @@ class ElementParser { Tag tag_; string elementStart; - string s; + string* s; Handler commentHandler = null; Handler cdataHandler = null; @@ -1766,7 +1766,7 @@ class ElementParser } // Private constructor for empty tags - this(Tag tag, string t) @safe @nogc pure nothrow + this(Tag tag, string* t) @safe @nogc pure nothrow { s = t; this(); @@ -1849,7 +1849,7 @@ class ElementParser protected this() @safe @nogc pure nothrow { - elementStart = s; + elementStart = *s; } /** @@ -2005,37 +2005,37 @@ class ElementParser while (s.length != 0) { - if (startsWith(s,"")); + chop(*s,4); + t = chop(*s,indexOf(*s,"-->")); if (commentHandler.funcptr !is null) commentHandler(t); - chop(s,3); + chop(*s,3); } - else if (startsWith(s,"")); + chop(*s,9); + t = chop(*s,indexOf(*s,"]]>")); if (cdataHandler.funcptr !is null) cdataHandler(t); - chop(s,3); + chop(*s,3); } - else if (startsWith(s,"")); + chop(*s,2); + t = chop(*s,indexOf(*s,">")); if (xiHandler.funcptr !is null) xiHandler(t); - chop(s,1); + chop(*s,1); } - else if (startsWith(s,"")); + chop(*s,2); + t = chop(*s,indexOf(*s,"?>")); if (piHandler.funcptr !is null) piHandler(t); - chop(s,2); + chop(*s,2); } - else if (startsWith(s,"<")) + else if (startsWith(*s,"<")) { - tag_ = new Tag(s,true); + tag_ = new Tag(*s,true); if (root is null) return; // Return to constructor of derived class @@ -2091,7 +2091,7 @@ class ElementParser // Handle the pretend start tag string s2; - auto parser = new ElementParser(startTag,s2); + auto parser = new ElementParser(startTag,&s2); auto handler1 = startTag.name in onStartTag; if (handler1 !is null) (*handler1)(parser); else @@ -2113,7 +2113,7 @@ class ElementParser } else { - t = chop(s,indexOf(s,"<")); + t = chop(*s,indexOf(*s,"<")); if (rawTextHandler.funcptr !is null) rawTextHandler(t); else if (textHandler.funcptr !is null) From c7b6b87333fe731962f38a8a6ac0a3b5f675be06 Mon Sep 17 00:00:00 2001 From: anonymous Date: Thu, 15 Jun 2017 21:08:03 +0200 Subject: [PATCH 2/2] test against regression fixes issue 17511 --- std/xml.d | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/std/xml.d b/std/xml.d index d55c6661857..770c56fdbfb 100644 --- a/std/xml.d +++ b/std/xml.d @@ -1727,6 +1727,14 @@ class DocumentParser : ElementParser } } +@system unittest +{ + auto doc = new Document(""); + assert(doc.elements.length == 1); + assert(doc.elements[0].tag.name == "child"); + assert(doc.items == doc.elements); +} + /** * Class for parsing an XML element. *