Don't preserve XML instruction declarations inside JSON narrative blocks

This commit is contained in:
James Agnew 2020-01-07 10:59:30 -05:00
parent d3cf93cf04
commit 746e249346
2 changed files with 13 additions and 0 deletions

View File

@ -397,6 +397,10 @@ public class XhtmlNode implements IBaseXhtml {
XhtmlDocument fragment = new XhtmlParser().parse(val, "div");
this.attributes = fragment.getAttributes();
this.childNodes = fragment.getChildNodes();
// Strip the <? .. ?> declaration if one was present
if (childNodes.size() > 0 && childNodes.get(0) != null && childNodes.get(0).getNodeType() == NodeType.Instruction) {
childNodes.remove(0);
}
this.content = fragment.getContent();
this.name = fragment.getName();
this.nodeType= fragment.getNodeType();

View File

@ -46,5 +46,14 @@ public class XhtmlNodeTest {
}
@Test
public void testProcessingInstructionNotPreserved() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
}