You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The spring boot mustache view resolver accepts a charset parameter (via MustacheProperties), but that parameter is only used by the template loader, it is not used as part of the response content type. The default returned content type is text/html (with no charset), since that's the content type set on the ViewResolver in MustacheServletWebConfiguration.
In spring boot 2, this fell back on jetty's default implied charset list, via jetty's MimeTypes.getCharsetInferredFromContentType. By default, jetty returns utf-8 for text/html, which effectively made the response headers contain Content-Type: text/html;charset=utf-8. All was happy.
However, in spring boot 3, this added line totally wipes out jetty's inferred charset list. This causes jetty to fall back to it's hard-coded last resort charset, ISO-8859-1 (see jetty's ServletContextResponse ).
This means that in spring boot 3, all mustache templates are rendered using utf8, but return an iso-8859-1 content type header, which is incorrect and breaks all non-latin characters.
The text was updated successfully, but these errors were encountered:
mmorrisontx
changed the title
Mustache templates return with ISO-8859-1 charset rather than UTF-8
Mustache templates return with ISO-8859-1 charset rather than UTF-8 in Content-Type response header
Feb 4, 2025
It seems that this issue doesn't exist in other template systems like freemarker because FreeMarkerProperties extends from AbstractTemplateViewResolverProperties / AbstractViewResolverProperties, which handle this case properly by including their charset in the response from getContentType(). The 'proper' fix might be to refactor MustacheProperties to extend from AbstractTemplateViewResolverProperties as well.
The 'proper' fix might be to refactor MustacheProperties to extend from AbstractTemplateViewResolverProperties as well.
Unfortunately, we can't do that because Mustache is supported with both the reactive and servlet web stacks and the structure of AbstractTemplateViewResolverProperties is servlet-only.
The spring boot mustache view resolver accepts a charset parameter (via MustacheProperties), but that parameter is only used by the template loader, it is not used as part of the response content type. The default returned content type is
text/html
(with no charset), since that's the content type set on the ViewResolver in MustacheServletWebConfiguration.In spring boot 2, this fell back on jetty's default implied charset list, via jetty's MimeTypes.getCharsetInferredFromContentType. By default, jetty returns
utf-8
fortext/html
, which effectively made the response headers containContent-Type: text/html;charset=utf-8
. All was happy.However, in spring boot 3, this added line totally wipes out jetty's inferred charset list. This causes jetty to fall back to it's hard-coded last resort charset,
ISO-8859-1
(see jetty's ServletContextResponse ).This means that in spring boot 3, all mustache templates are rendered using utf8, but return an iso-8859-1 content type header, which is incorrect and breaks all non-latin characters.
The text was updated successfully, but these errors were encountered: