don't escape umlaut in elem utf8

This commit is contained in:
Oliver Egger 2020-06-10 18:07:03 +02:00
parent b01c64dc2c
commit ebc2a7a6ba
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));
}
}