Correctly handle narratives where the XHTML namespace is bound to a dumb
prefix
This commit is contained in:
parent
746e249346
commit
cf82025c0d
|
@ -473,7 +473,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
||||||
readChar();
|
readChar();
|
||||||
} else {
|
} else {
|
||||||
unwindPoint = null;
|
unwindPoint = null;
|
||||||
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
|
List<XhtmlNode> p = new ArrayList<>();
|
||||||
parseElementInner(root, p, nsm, true);
|
parseElementInner(root, p, nsm, true);
|
||||||
}
|
}
|
||||||
return result;
|
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
|
// 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
|
// 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);
|
NSMap result = new NSMap(nsm);
|
||||||
List<String> nsattrs = new ArrayList<String>();
|
List<String> nsattrs = new ArrayList<String>();
|
||||||
for (String an : node.getAttributes().keySet()) {
|
for (String an : node.getAttributes().keySet()) {
|
||||||
|
|
|
@ -2,11 +2,15 @@ package org.hl7.fhir.utilities.tests;
|
||||||
|
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class XhtmlNodeTest {
|
public class XhtmlNodeTest {
|
||||||
|
|
||||||
|
private static final Logger ourLog = LoggerFactory.getLogger(XhtmlNodeTest.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See https://github.com/jamesagnew/hapi-fhir/issues/1488
|
* 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());
|
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
|
@Test
|
||||||
public void testParseRsquo() {
|
public void testParseRsquo() {
|
||||||
XhtmlNode dt = new XhtmlNode();
|
XhtmlNode dt = new XhtmlNode();
|
||||||
|
@ -45,7 +48,6 @@ public class XhtmlNodeTest {
|
||||||
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">It’s January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
|
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">It’s January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstructionNotPreserved() {
|
public void testProcessingInstructionNotPreserved() {
|
||||||
XhtmlNode dt = new XhtmlNode();
|
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());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue