From 65d8c76ac35aa8da45f4f648c3bab493ba2b5969 Mon Sep 17 00:00:00 2001 From: Chris Hut Date: Mon, 4 Apr 2022 17:35:15 -0700 Subject: [PATCH] Add Tomcat locale mapping for Japanese to preserve UTF-8 charset See gh-30535 --- .../boot/web/embedded/tomcat/TomcatServletWebServerFactory.java | 1 + .../web/embedded/tomcat/TomcatServletWebServerFactoryTests.java | 1 + 2 files changed, 2 insertions(+) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index 3cd2cc552e..edef53c498 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -260,6 +260,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto private void resetDefaultLocaleMapping(TomcatEmbeddedContext context) { context.addLocaleEncodingMappingParameter(Locale.ENGLISH.toString(), DEFAULT_CHARSET.displayName()); context.addLocaleEncodingMappingParameter(Locale.FRENCH.toString(), DEFAULT_CHARSET.displayName()); + context.addLocaleEncodingMappingParameter(Locale.JAPANESE.toString(), DEFAULT_CHARSET.displayName()); } private void addLocaleMappings(TomcatEmbeddedContext context) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index 83a2d12a9b..73c12183f6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -411,6 +411,7 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory // override defaults, see org.apache.catalina.util.CharsetMapperDefault.properties assertThat(getCharset(Locale.ENGLISH)).isEqualTo(StandardCharsets.UTF_8); assertThat(getCharset(Locale.FRENCH)).isEqualTo(StandardCharsets.UTF_8); + assertThat(getCharset(Locale.JAPANESE)).isEqualTo(StandardCharsets.UTF_8); } @Test