Skip to content

Commit dd748ed

Browse files
committed
Use the configured charset, if any, in MustacheViewResolver
Closes gh-2670
1 parent 2cf23e0 commit dd748ed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler) {
108108
resolver.setCache(this.mustache.isCache());
109109
resolver.setViewNames(this.mustache.getViewNames());
110110
resolver.setContentType(this.mustache.getContentType());
111+
resolver.setCharset(this.mustache.getCharset());
111112
resolver.setCompiler(mustacheCompiler);
112113
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
113114
return resolver;

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
* Spring MVC {@link ViewResolver} for Mustache.
3535
*
3636
* @author Dave Syer
37+
* @author Andy Wilkinson
3738
* @since 1.2.2
3839
*/
3940
public class MustacheViewResolver extends UrlBasedViewResolver {
4041

4142
private Compiler compiler = Mustache.compiler();
4243

44+
private String charset;
45+
4346
public MustacheViewResolver() {
4447
setViewClass(MustacheView.class);
4548
}
@@ -51,6 +54,13 @@ public void setCompiler(Compiler compiler) {
5154
this.compiler = compiler;
5255
}
5356

57+
/**
58+
* @param charset the charset to set
59+
*/
60+
public void setCharset(String charset) {
61+
this.charset = charset;
62+
}
63+
5464
@Override
5565
protected View loadView(String viewName, Locale locale) throws Exception {
5666
Resource resource = resolveResource(viewName, locale);
@@ -64,7 +74,9 @@ protected View loadView(String viewName, Locale locale) throws Exception {
6474
}
6575

6676
private Template createTemplate(Resource resource) throws IOException {
67-
return this.compiler.compile(new InputStreamReader(resource.getInputStream()));
77+
return this.charset == null ? this.compiler.compile(new InputStreamReader(
78+
resource.getInputStream())) : this.compiler
79+
.compile(new InputStreamReader(resource.getInputStream(), this.charset));
6880
}
6981

7082
private Resource resolveResource(String viewName, Locale locale) {

0 commit comments

Comments
 (0)