Skip to content

Commit c0f5809

Browse files
ddongjunnsnicoll
authored andcommitted
Use Charset instead of String for Mustache templates support
The MustacheResourceTemplateLoader previously defined the template encoding as a String, defaulting to "UTF-8". This change replaces the field with a Charset and initializes it with StandardCharsets.UTF_8. Using Charset improves type safety and aligns with modern Spring Boot standards, while avoiding implicit charset lookup issues. See spring-projectsgh-48347 Signed-off-by: djlee <ddongjunn@gmail.com>
1 parent 811ddcd commit c0f5809

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public Charset getCharset() {
124124
return this.charset;
125125
}
126126

127+
/**
128+
* Get the charset name.
129+
* @return the charset name
130+
* @deprecated since 4.1.0 in favor of {@link #getCharset()}
131+
*/
132+
@Deprecated(since = "4.1.0")
127133
public String getCharsetName() {
128134
return this.charset.name();
129135
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.InputStreamReader;
2020
import java.io.Reader;
21+
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2123

2224
import com.samskivert.mustache.Mustache;
2325
import com.samskivert.mustache.Mustache.Compiler;
@@ -45,7 +47,7 @@ public class MustacheResourceTemplateLoader implements TemplateLoader, ResourceL
4547

4648
private String suffix = "";
4749

48-
private String charSet = "UTF-8";
50+
private Charset charSet = StandardCharsets.UTF_8;
4951

5052
private ResourceLoader resourceLoader = new DefaultResourceLoader(null);
5153

@@ -60,8 +62,19 @@ public MustacheResourceTemplateLoader(String prefix, String suffix) {
6062
/**
6163
* Set the charset.
6264
* @param charSet the charset
65+
* @deprecated since 4.1.0 in favor of {@link #setCharset(Charset)}
6366
*/
67+
@Deprecated(since = "4.1.0")
6468
public void setCharset(String charSet) {
69+
this.charSet = Charset.forName(charSet);
70+
}
71+
72+
/**
73+
* Set the charset.
74+
* @param charSet the charset
75+
* @since 4.1.0
76+
*/
77+
public void setCharset(Charset charSet) {
6578
this.charSet = charSet;
6679
}
6780

0 commit comments

Comments
 (0)