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 c8dfd6105..a47df8aea 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 @@ -362,7 +362,7 @@ public class XhtmlNode implements IBaseXhtml { return null; } try { - String retVal = new XhtmlComposer(XhtmlComposer.HTML).compose(this); + String retVal = new XhtmlComposer(XhtmlComposer.XML).compose(this); retVal = XhtmlDt.preprocessXhtmlNamespaceDeclaration(retVal); return retVal; } catch (Exception e) { diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java new file mode 100644 index 000000000..c5871b2c6 --- /dev/null +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java @@ -0,0 +1,28 @@ +package org.hl7.fhir.utilities.xhtml; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class XhtmlNodeTest { + + /** + * See https://github.com/jamesagnew/hapi-fhir/issues/1488 + */ + @Test + public void testDontEncodeHtmlOnlyEntities() { + + // Entity that appears in XHTML not not in XML + XhtmlNode node = new XhtmlNode(); + node.setValueAsString("
®
"); + assertEquals("
®
", node.getValueAsString()); + + // Entity that appears in both + node = new XhtmlNode(); + node.setValueAsString("
<
"); + assertEquals("
<
", node.getValueAsString()); + + } + + +} \ No newline at end of file