Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative fix for #41 "<tag></tag>" parsed as if it were nothing #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}