Opened 15 years ago
Closed 15 years ago
#8644 closed defect (fixed)
Missing character encoding in <html> tag
Reported by: | Mitar | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 0.12 |
Component: | rendering | Version: | 0.11.4 |
Severity: | minor | Keywords: | |
Cc: | mmitar@…, Christopher Lenz | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
W3C validator recommends:
No character encoding information was found within the document, either in an HTML meta element or an XML declaration. It is often recommended to declare the character encoding in the document itself, especially if there is a chance that the document will be read from or saved to disk, CD, etc.
We could add character encoding to <html>
tag.
Attachments (0)
Change History (11)
comment:1 by , 15 years ago
Cc: | added |
---|---|
Milestone: | → 0.12 |
comment:3 by , 15 years ago
All pages generated by Trac from templates are using the utf-8 encoding.
comment:4 by , 15 years ago
Owner: | set to |
---|---|
Severity: | normal → minor |
From the Specifying Character Encoding article at webstandards.org:
…
- Best.
- The character encoding is properly set at the server level, either with a default that authors can override or on a per-document basis, and is also available at the document level (both in the XML declaration if applicable and the meta element) for standalone use
comment:6 by , 15 years ago
Replying to cboos:
Fixed in r8577.
Wow, are you sure you won't introduce issue with this "fix"?
Now the document is declared as text/html
, what about if the document is declared as a XML document?
From http://www.w3.org/International/tutorials/tutorial-char-enc/#Slide0250, it seems that for example, this change would break the th:RevtreePlugin
follow-up: 8 comment:7 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I didn't know that. IIUC, when the Content-Type is declared as xml, we should output a XML declaration to convey the content encoding information (and not have the <meta>, of course).
comment:8 by , 15 years ago
Replying to cboos:
I didn't know that. IIUC, when the Content-Type is declared as xml, we should output a XML declaration to convey the content encoding information (and not have the <meta>, of course).
AFAICT, the only way to output SVG data embedded into a Trac page is to declare the XHTML page content as an XML document type (which is valid). In this case, the <meta>
tag becomes invalid.
To solve the initial issue, either the encoding type should be declared the "XML way", or the content type of the document should be checked first, before applying the <meta>
tag.
follow-up: 10 comment:9 by , 15 years ago
So what about this?
-
trac/templates/layout.html
10 10 <title py:with="title = list(select('title/text()'))"> 11 11 <py:if test="title">${title} ΓÇô </py:if>${project.name or 'Trac'} 12 12 </title> 13 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />13 <meta py:if="chrome.content_type == 'text/html'" http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 14 14 <py:if test="chrome.links"> 15 15 <py:for each="rel, links in chrome.links.items()"> 16 16 <link rel="${rel}" py:for="link in links" py:attrs="link" /> -
trac/web/chrome.py
767 767 768 768 template = self.load_template(filename, method=method) 769 769 data = self.populate_data(req, data) 770 data['chrome']['content_type'] = content_type 770 771 771 772 stream = template.generate(**data) 772 773 … … 800 801 801 802 try: 802 803 buffer = cStringIO() 804 if method == 'xml': 805 buffer.write('<?xml version="1.0" encoding="utf-8" ?>') 803 806 stream.render(method, doctype=doctype, out=buffer) 804 807 return buffer.getvalue().translate(_translate_nop, 805 808 _invalid_control_chars)
comment:10 by , 15 years ago
Replying to cboos:
So what about this?
It seems ok, I'll try to perform some tests as soon as I get some spare time…
comment:11 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Committed the patch above in [8618].
Please reopen if there's still a problem with this.
The fix would be trivial:
trac/templates/layout.html
It seems to work fine, the pages now validate without warning, but … I'm not sure, maybe there was a good reason I don't know about why this was not done in the first place.