From 407ae3b04f919185b597047c75e3fdc325808eff Mon Sep 17 00:00:00 2001 From: Guirong Hu Date: Fri, 15 Apr 2022 15:22:30 +0800 Subject: [PATCH 1/2] Validate overrides against CharsetMapperDefault.properties See gh-30692 --- .../tomcat/TomcatServletWebServerFactoryTests.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 73c12183f6..9ac522eaf6 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 @@ -27,6 +27,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Properties; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicReference; @@ -405,13 +406,15 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory } @Test - void defaultLocaleCharsetMappingsAreOverridden() { + void defaultLocaleCharsetMappingsAreOverridden() throws IOException { TomcatServletWebServerFactory factory = getFactory(); this.webServer = factory.getWebServer(); // 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); + Properties charsetMapperDefault = new Properties(); + charsetMapperDefault.load(CharsetMapper.class.getResourceAsStream("CharsetMapperDefault.properties")); + for (String language : charsetMapperDefault.stringPropertyNames()) { + assertThat(getCharset(new Locale(language))).isEqualTo(StandardCharsets.UTF_8); + } } @Test From 1fa4701d6dd9c017b332a4531eb9af406619bcf1 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 19 Apr 2022 09:03:54 +0200 Subject: [PATCH 2/2] Polish "Validate overrides against CharsetMapperDefault.properties" See gh-30692 --- .../embedded/tomcat/TomcatServletWebServerFactoryTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 9ac522eaf6..468209c8cd 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 @@ -81,6 +81,8 @@ import org.springframework.boot.web.server.WebServerException; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests; import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -410,8 +412,8 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory TomcatServletWebServerFactory factory = getFactory(); this.webServer = factory.getWebServer(); // override defaults, see org.apache.catalina.util.CharsetMapperDefault.properties - Properties charsetMapperDefault = new Properties(); - charsetMapperDefault.load(CharsetMapper.class.getResourceAsStream("CharsetMapperDefault.properties")); + Properties charsetMapperDefault = PropertiesLoaderUtils + .loadProperties(new ClassPathResource("CharsetMapperDefault.properties", CharsetMapper.class)); for (String language : charsetMapperDefault.stringPropertyNames()) { assertThat(getCharset(new Locale(language))).isEqualTo(StandardCharsets.UTF_8); }