Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#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)

Change History (3)

comment:1 Changed 12 years ago by osimons

Thanks for reporting. You are correct in that the output is ambiguous without some declaration of encoding.

  1. If we want UTF-8 always, I should really do .encode('utf-8') on the string explicitly.
  1. Your suggestion will do doubt work, but technically the <meta> tag needs to be wrapped in a <head> tag according to W3C specification. Trivial detail though.
  1. The idea of an API is of course that it should be a machine-to-machine interface, so technically the API can just specify and have the client adjust. Browser rendering is less of an issue with an API as it isn't intended for direct consumption. Yet another alternative would just to 1. above, and have the doc say: "Returns page rendered as HTML (UTF-8 encoded)..." or something to that effect.

Would that suffice? Explicit encode + update docs? As long as the client can rely on UTF-8 there should be no ambiguity, right?

comment:2 Changed 12 years ago by nashville_parent

Yep, that sounds sensible to me.

comment:3 Changed 12 years ago by osimons

Resolution: fixed
Status: newclosed

Fixed in [12107].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain osimons.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.