Correctly handle narratives where the XHTML namespace is bound to a dumb

prefix
This commit is contained in:
James Agnew 2020-01-07 13:36:33 -05:00
parent 746e249346
commit cf82025c0d
2 changed files with 18 additions and 6 deletions

View File

@ -473,7 +473,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
readChar();
} else {
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(root, p, nsm, true);
}
return result;
@ -489,9 +489,6 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
// what we do here is strip out any stated namespace attributes, putting them in the namesapce map
// then we figure out what the namespace of this element is, and state it explicitly if it's not the default
// but we don't bother with any of this if we're not validating
if (!validatorMode)
return null;
NSMap result = new NSMap(nsm);
List<String> nsattrs = new ArrayList<String>();
for (String an : node.getAttributes().keySet()) {

View File

@ -2,11 +2,15 @@ package org.hl7.fhir.utilities.tests;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
public class XhtmlNodeTest {
private static final Logger ourLog = LoggerFactory.getLogger(XhtmlNodeTest.class);
/**
* See https://github.com/jamesagnew/hapi-fhir/issues/1488
*/
@ -36,7 +40,6 @@ public class XhtmlNodeTest {
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testParseRsquo() {
XhtmlNode dt = new XhtmlNode();
@ -45,7 +48,6 @@ public class XhtmlNodeTest {
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testProcessingInstructionNotPreserved() {
XhtmlNode dt = new XhtmlNode();
@ -54,6 +56,19 @@ public class XhtmlNodeTest {
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testParseXhtmlQualified() {
XhtmlNode node = new XhtmlNode();
node.setValueAsString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">" +
"<xhtml:img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>" +
"@fhirabend" +
"</xhtml:div>");
String output = node.getValueAsString();
ourLog.info(output);
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output);
}
}