Apply charset to Mustache's content type

Fixes gh-44053
This commit is contained in:
Andy Wilkinson
2025-02-10 10:52:56 +00:00
parent 89f5bf9c64
commit ea76e46faa
2 changed files with 30 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -117,6 +117,7 @@ class MustacheAutoConfigurationTests {
assertThat(viewResolver).extracting("allowSessionOverride", InstanceOfAssertFactories.BOOLEAN).isFalse();
assertThat(viewResolver).extracting("cache", InstanceOfAssertFactories.BOOLEAN).isFalse();
assertThat(viewResolver).extracting("charset").isEqualTo("UTF-8");
assertThat(viewResolver).extracting("contentType").isEqualTo("text/html;charset=UTF-8");
assertThat(viewResolver).extracting("exposeRequestAttributes", InstanceOfAssertFactories.BOOLEAN).isFalse();
assertThat(viewResolver).extracting("exposeSessionAttributes", InstanceOfAssertFactories.BOOLEAN).isFalse();
assertThat(viewResolver).extracting("exposeSpringMacroHelpers", InstanceOfAssertFactories.BOOLEAN).isTrue();
@@ -161,6 +162,10 @@ class MustacheAutoConfigurationTests {
@EnumSource(ViewResolverKind.class)
void charsetCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
assertViewResolverProperty(kind, "spring.mustache.charset=UTF-16", "charset", "UTF-16");
if (kind == ViewResolverKind.SERVLET) {
assertViewResolverProperty(kind, "spring.mustache.charset=UTF-16", "contentType",
"text/html;charset=UTF-16");
}
}
@Test