Skip to content

Commit

Permalink
Fix for 3.1.2.10 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored Jun 10, 2024
1 parent ab7617c commit 8ea5866
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.openmrs.module.attachments.AttachmentsContext.getContentFamily;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import javax.servlet.http.HttpServletResponse;

Expand All @@ -23,6 +24,7 @@
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.openmrs.obs.ComplexData;
import org.openmrs.web.WebUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -69,7 +71,12 @@ public void getFile(@PathVariable("uuid") String uuid, @RequestParam(required =
response.addHeader("File-Ext", getExtension(attComplexData.getTitle(), mimeType));

try {
response.getOutputStream().write(attComplexData.asByteArray());
byte[] bytes = attComplexData.asByteArray();
if (mimeType != null && mimeType.startsWith("text")) {
String byteString = WebUtil.encodeForHtmlContent(new String(bytes, StandardCharsets.UTF_8));
bytes = byteString.getBytes(StandardCharsets.UTF_8);
}
response.getOutputStream().write(bytes);
}
catch (IOException ex) {
response.setStatus(500);
Expand Down

0 comments on commit 8ea5866

Please sign in to comment.