Modify ↓
      
        #10340 closed defect (fixed)
Specify character encoding in pages returned by wiki.getPageHTML
| Reported by: | nashville_parent | Owned by: | osimons | 
|---|---|---|---|
| Priority: | normal | Component: | XmlRpcPlugin | 
| Severity: | normal | Keywords: | encoding, utf8, utf-8 | 
| Cc: | Olemis Lang | Trac Release: | 1.0 | 
Description
No character encoding is specified in the HTML returned by wiki.getPageHTML / wiki.getPageHTMLVersion.
By default, Trac appears to use UTF-8 encoding throughout (see page template here), however this is not necessarily the encoding which is used by the web-browser viewing the generated file. For example, my copy of Internet Explorer attempts to render it as Western European (Windows) when encoding auto-select is enabled.
To resolve this, it appears that we can simply change wiki.py line 115 (as at r11148) from -
return '<html><body>%s</body></html>' % html
to:
return '<html><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><body>%s</body></html>' % html
Attachments (0)
Note: See
        TracTickets for help on using
        tickets.
    


Thanks for reporting. You are correct in that the output is ambiguous without some declaration of encoding.
.encode('utf-8')on the string explicitly.<meta>tag needs to be wrapped in a<head>tag according to W3C specification. Trivial detail though.Would that suffice? Explicit encode + update docs? As long as the client can rely on UTF-8 there should be no ambiguity, right?