Skip to content

Commit

Permalink
Alternative fix for lodo1995#41 "<tag></tag>" parsed as if it were no…
Browse files Browse the repository at this point in the history
…thing
  • Loading branch information
Daniel Kozák committed Jul 27, 2017
1 parent 0ab3681 commit 5d33ba3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion source/std/experimental/xml/cursor.d
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ struct Cursor(P, Flag!"conflateCDATA" conflateCDATA = Yes.conflateCDATA, ErrorHa
}
else if (currentNode.kind == XMLKind.elementStart)
{
return advanceInput() && currentNode.kind != XMLKind.elementEnd;
advanceInput();
if (currentNode.kind != XMLKind.elementEnd)
return true;
currentNode.kind = XMLKind.elementEmpty;
return false;
}
else if (currentNode.kind == XMLKind.dtdStart)
{
Expand Down
28 changes: 27 additions & 1 deletion source/std/experimental/xml/domparser.d
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,30 @@ unittest

assert(doc.getElementsByTagName("ccc").length == 1);
assert(doc.documentElement.getAttribute("xmlns:myns") == "something");
}
}

unittest
{
import std.experimental.xml.lexers;
import std.experimental.xml.parser;
import std.experimental.xml.cursor;
import std.experimental.allocator.gc_allocator;
import domimpl = std.experimental.xml.domimpl;

alias DOMImplType = domimpl.DOMImplementation!string;

auto xml = `<?xml version="1.0" encoding="UTF-8"?><tag></tag>`;
auto builder =
xml
.lexer
.parser
.cursor
.copyingCursor
.domBuilder(new DOMImplType());

builder.setSource(xml);
builder.buildRecursive;
auto doc = builder.getDocument;

assert(doc.childNodes.length == 1);
}

0 comments on commit 5d33ba3

Please sign in to comment.