Work on https://github.com/jamesagnew/hapi-fhir/issues/1658 - Make sure
we preserve lang attribute on narrative div
This commit is contained in:
parent
9c1a6e61e6
commit
d3cf93cf04
|
@ -394,13 +394,12 @@ public class XhtmlNode implements IBaseXhtml {
|
|||
val = XhtmlDt.preprocessXhtmlNamespaceDeclaration(val);
|
||||
|
||||
try {
|
||||
// TODO: this is ugly
|
||||
XhtmlNode fragment = new XhtmlParser().parseFragment(val);
|
||||
this.attributes = fragment.attributes;
|
||||
this.childNodes = fragment.childNodes;
|
||||
this.content = fragment.content;
|
||||
this.name = fragment.name;
|
||||
this.nodeType= fragment.nodeType;
|
||||
XhtmlDocument fragment = new XhtmlParser().parse(val, "div");
|
||||
this.attributes = fragment.getAttributes();
|
||||
this.childNodes = fragment.getChildNodes();
|
||||
this.content = fragment.getContent();
|
||||
this.name = fragment.getName();
|
||||
this.nodeType= fragment.getNodeType();
|
||||
} catch (Exception e) {
|
||||
// TODO: composer shouldn't throw exception like this
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -54,6 +54,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -446,7 +447,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
|||
}
|
||||
|
||||
public XhtmlDocument parse(InputStream input, String entryName) throws FHIRFormatError, IOException {
|
||||
rdr = new InputStreamReader(input, "UTF-8");
|
||||
rdr = new InputStreamReader(input, StandardCharsets.UTF_8);
|
||||
return parse(entryName);
|
||||
}
|
||||
|
||||
|
@ -1176,7 +1177,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
|||
String n = readName().toLowerCase();
|
||||
readToTagEnd();
|
||||
XhtmlNode result = new XhtmlNode(NodeType.Element);
|
||||
|
||||
|
||||
int colonIndex = n.indexOf(':');
|
||||
if (colonIndex != -1) {
|
||||
n = n.substring(colonIndex + 1);
|
||||
|
@ -1184,7 +1185,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
|||
|
||||
result.setName(n);
|
||||
unwindPoint = null;
|
||||
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
|
||||
List<XhtmlNode> p = new ArrayList<>();
|
||||
parseElementInner(result, p, null, true);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package org.hl7.fhir.utilities.tests;
|
||||
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class XhtmlNodeTest {
|
||||
|
||||
|
@ -26,5 +25,26 @@ public class XhtmlNodeTest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://github.com/jamesagnew/hapi-fhir/issues/1658
|
||||
*/
|
||||
@Test
|
||||
public void testLangAttributePreserved() {
|
||||
XhtmlNode dt = new XhtmlNode();
|
||||
dt.setValueAsString("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>");
|
||||
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", dt.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
|
||||
public void testParseRsquo() {
|
||||
XhtmlNode dt = new XhtmlNode();
|
||||
dt.setValueAsString("It’s January again");
|
||||
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">It’s January again</div>", dt.getValueAsString());
|
||||
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">It’s January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue