From ecfdf43034b2aa47d36625efe1e923adbf52b621 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 21 Oct 2019 11:10:59 -0400 Subject: [PATCH] Fix https://github.com/jamesagnew/hapi-fhir/issues/1488 - We should not use HTML encoding on entities when serializing narratives --- .../hl7/fhir/utilities/xhtml/XhtmlNode.java | 2 +- .../fhir/utilities/xhtml/XhtmlNodeTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlNodeTest.java 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