From ebc2a7a6ba4bde60d2900f168d662d52d8753d00 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Wed, 10 Jun 2020 18:07:03 +0200 Subject: [PATCH] don't escape umlaut in elem utf8 --- .../hl7/fhir/r5/test/CDARoundTripTests.java | 25 +++++++++++++++++++ .../org/hl7/fhir/utilities/xml/XMLWriter.java | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java index 57d676eb7..94f49a943 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java @@ -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 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); + } } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java index 0dc6535ba..107638ef5 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java @@ -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)); } }