we preserve lang attribute on narrative div
This commit is contained in:
James Agnew 2020-01-07 09:53:43 -05:00
parent 9c1a6e61e6
commit d3cf93cf04
3 changed files with 33 additions and 13 deletions

View File

@ -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);

View File

@ -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);
}
@ -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;

View File

@ -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&rsquo;s January again");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
}