From 67e242b96778e0b3c59648b5dbf834e66d37f512 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 13 May 2026 17:32:27 +0200 Subject: [PATCH] [OLMIS-8223] Fix apostrophe bug in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Overrode createMessageFormat in ExposedMessageSourceImpl files across 14 repos (auth, buq, cce, dhis2-integration, diagnostics, fulfillment, hapifhir, notification, referencedata, report, requisition, stockmanagement, template-service, one-network-integration-service). When an exception with a Message invokes, @ControllerAdvice calls messageSource.getMessage(), which Spring resolves by calling createMessageFormat() — which I override. It detects singular `'` in messages and converts them to `''`. Escaped `''` in messages remain unchanged. To test I built requisition and referencedata, switched to :latest in ref-distro, then tested with requests: ``` GET /api/requisitions/search?requisitionStatus=BOGUS Accept-Language: fr Authorization: Bearer ``` Response — 400 Bad Request: ```json { "messageKey": "requisition.error.validation.params.requisitionStatus.notValidStatus", "message": "Le paramètre \"requisitionStatus\" n'est pas un Statut de Demande d'achat valide: [BOGUS]." } ``` And: ``` POST /api/requisitions/initiate?facility=00000000-0000-0000-0000-000000000000&program=00000000-0000-0000-0000-000000000000&suggestedPeriod=00000000-0000-0000-0000-000000000000&emergency=false Accept-Language: fr Authorization: Bearer ``` Response — 500 Internal Server Error (requisition wraps a 400 from referencedata): ```json { "status": 500, "error": "Internal Server Error", "message": "400 : [{\n \"messageKey\" : \"referenceData.error.program.notFound.with.id\",\n \"message\" : \"Impossible de trouver le programme avec l'ID : 00000000-0000-0000-0000-000000000000\"\n}]", "path": "/api/requisitions/initiate" } ``` Apostrophes are preserved, and `{0}` placeholders are replaced. Includes unit test ExposedMessageSourceImplTest. --- .../report/i18n/ExposedMessageSourceImpl.java | 9 +++++ .../i18n/ExposedMessageSourceImplTest.java | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/test/java/org/openlmis/report/i18n/ExposedMessageSourceImplTest.java diff --git a/src/main/java/org/openlmis/report/i18n/ExposedMessageSourceImpl.java b/src/main/java/org/openlmis/report/i18n/ExposedMessageSourceImpl.java index 4a423e7..9d182f9 100644 --- a/src/main/java/org/openlmis/report/i18n/ExposedMessageSourceImpl.java +++ b/src/main/java/org/openlmis/report/i18n/ExposedMessageSourceImpl.java @@ -15,12 +15,14 @@ package org.openlmis.report.i18n; +import java.text.MessageFormat; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Properties; import org.springframework.context.support.ReloadableResourceBundleMessageSource; +import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @Component @@ -33,6 +35,13 @@ protected Properties getAllProperties(Locale locale) { return propertiesHolder.getProperties(); } + @Override + @NonNull + protected MessageFormat createMessageFormat(@NonNull String msg, @NonNull Locale locale) { + String safe = msg.replaceAll("(?