From 746e249346928177dfde01de82327c9cb457dad0 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 7 Jan 2020 10:59:30 -0500 Subject: [PATCH] Don't preserve XML instruction declarations inside JSON narrative blocks --- .../java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java | 4 ++++ .../java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java index 0b01556d3..ff5b3f10e 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java @@ -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(); diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java index 9a405349a..bee8fe594 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java @@ -46,5 +46,14 @@ public class XhtmlNodeTest { } + @Test + public void testProcessingInstructionNotPreserved() { + XhtmlNode dt = new XhtmlNode(); + dt.setValueAsString("
help i'm a bug
"); + assertEquals("
help i'm a bug
", dt.getValueAsString()); + assertEquals("
help i'm a bug
", new XhtmlNode().setValue(dt.getValue()).getValueAsString()); + } + + } \ No newline at end of file