Merge pull request #239 from ahdis/oe_xmlwriter_utf8_elem

XmlWriter for UTF-8 should not encode umlaut in elements (elementmodel)
This commit is contained in:
Grahame Grieve 2020-06-11 21:57:08 +10:00 committed by GitHub
commit f5b749f523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package org.hl7.fhir.r5.test;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
@ -238,5 +241,27 @@ public class CDARoundTripTests {
assertsExample(cdaJsonRoundtrip);
}
@Test
/**
* verify that umlaut like äö etc are not encoded in UTF-8 in attributes
*/
public void testSerializeUmlaut() throws IOException {
Element xml = Manager.parse(context,
TestingUtilities.loadTestResourceStream("validator", "cda", "example.xml"), FhirFormat.XML);
List<Element> title = xml.getChildrenByName("title");
assertTrue(title != null && title.size() == 1);
Element value = title.get(0).getChildren().get(0);
Assertions.assertEquals("Episode Note", value.getValue());
value.setValue("öé");
ByteArrayOutputStream baosXml = new ByteArrayOutputStream();
Manager.compose(TestingUtilities.context(), xml, baosXml, FhirFormat.XML, OutputStyle.PRETTY, null);
String cdaSerialised = baosXml.toString("UTF-8");
assertTrue(cdaSerialised.indexOf("öé") > 0);
}
}

View File

@ -726,7 +726,7 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter {
if (dontEscape)
write(content);
else
write(XMLUtil.escapeXML(content, "US-ASCII", false));
write(XMLUtil.escapeXML(content, charset, false));
}
}