use HTML encoding on entities when serializing narratives
This commit is contained in:
James Agnew 2019-10-21 11:10:59 -04:00
parent 0b196e5188
commit ecfdf43034
2 changed files with 29 additions and 1 deletions

View File

@ -362,7 +362,7 @@ public class XhtmlNode implements IBaseXhtml {
return null; return null;
} }
try { try {
String retVal = new XhtmlComposer(XhtmlComposer.HTML).compose(this); String retVal = new XhtmlComposer(XhtmlComposer.XML).compose(this);
retVal = XhtmlDt.preprocessXhtmlNamespaceDeclaration(retVal); retVal = XhtmlDt.preprocessXhtmlNamespaceDeclaration(retVal);
return retVal; return retVal;
} catch (Exception e) { } catch (Exception e) {

View File

@ -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("<div>&reg;</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">®</div>", node.getValueAsString());
// Entity that appears in both
node = new XhtmlNode();
node.setValueAsString("<div>&lt;</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">&lt;</div>", node.getValueAsString());
}
}