codeconsole opened a new pull request, #15976:
URL: https://github.com/apache/grails-core/pull/15976

   `respond()` rendering HTML sets the response content type to the bare mime 
type name (`text/html`) — `DefaultHtmlRenderer` is the only renderer that skips 
`GrailsWebUtil.getContentType`; its JSON and XML siblings both append the 
charset.
   
   ### Effect
   
   A bare `text/html` leaves the response charset to the servlet container 
(ISO-8859-1 on Tomcat). GSP only applies its configured 
`text/html;charset=UTF-8` when the response has no content type yet, so it 
backs off — the response writer then encodes Latin-1 and **every non-Latin-1 
character on the page is written as a literal `?`** (Czech, Cyrillic, Thai, 
CJK; Latin-1-mappable accents survive, which makes the corruption easy to miss 
on Western-European pages).
   
   ### Why it went unnoticed
   
   - It only triggers when the `Accept` header negotiates a concrete HTML mime 
type. Browsers always send one; curl and most HTTP test clients send `Accept: 
*/*`, which negotiates `MimeType.ALL`, skips the content-type stamp, and gets a 
correct UTF-8 page.
   - The SiteMesh 2 filter historically masked it by unconditionally forcing 
UTF-8 onto decorated responses. The SiteMesh 3 view-resolver integration 
(#15975) deliberately respects the content type the application sets — exposing 
this latent bug on every scaffolded (`respond`-rendered) page.
   
   ### Fix
   
   Mirror `DefaultJsonRenderer`: an `encoding` property defaulting to 
`GrailsWebUtil.DEFAULT_ENCODING` (UTF-8), applied via 
`GrailsWebUtil.getContentType(mimeType.name, encoding)`.
   
   ### Verification
   
   - New spec pins `text/html;charset=UTF-8` on the negotiated render path 
(fails against the old code); `:grails-rest-transforms:test` and 
`:grails-controllers:test` green.
   - Live: a generated application's scaffolded page requested with a real 
browser `Accept` header serves all 18 locales `charset=UTF-8`, strict 
byte-validated (`slovenčina`, `čeština`, `русский`, `中文` intact); in Chrome, 
`document.characterSet` is now `UTF-8` and the locale dropdown renders every 
native name correctly.
   
   Related: #15974, #15975.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to