Edgewall Software
Modify

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 Christian Boos, 15 years ago

Cc: Christopher Lenz added
Milestone: 0.12

The fix would be trivial:

  • trac/templates/layout.html

    diff --git a/trac/templates/layout.html b/trac/templates/layout.html
    a b  
    1010    <title py:with="title = list(select('title/text()'))">
    1111      <py:if test="title">${title} ΓÇô </py:if>${project.name or 'Trac'}
    1212    </title>
     13    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    1314    <py:if test="chrome.links">
    1415      <py:for each="rel, links in chrome.links.items()">
    1516        <link rel="${rel}" py:for="link in links" py:attrs="link" />

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.

comment:2 by Mitar, 15 years ago

Probably because not everybody is using UTF-8?

comment:3 by Christian Boos, 15 years ago

All pages generated by Trac from templates are using the utf-8 encoding.

comment:4 by Christian Boos, 15 years ago

Owner: set to Christian Boos
Severity: normalminor

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:5 by Christian Boos, 15 years ago

Resolution: fixed
Status: newclosed

Fixed in r8577.

in reply to:  5 comment:6 by Emmanuel Blot, 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

comment:7 by Christian Boos, 15 years ago

Resolution: fixed
Status: closedreopened

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

in reply to:  7 comment:8 by Emmanuel Blot, 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.

comment:9 by Christian Boos, 15 years ago

So what about this?

  • trac/templates/layout.html

     
    1010    <title py:with="title = list(select('title/text()'))">
    1111      <py:if test="title">${title} ΓÇô </py:if>${project.name or 'Trac'}
    1212    </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" />
    1414    <py:if test="chrome.links">
    1515      <py:for each="rel, links in chrome.links.items()">
    1616        <link rel="${rel}" py:for="link in links" py:attrs="link" />
  • trac/web/chrome.py

     
    767767
    768768        template = self.load_template(filename, method=method)
    769769        data = self.populate_data(req, data)
     770        data['chrome']['content_type'] = content_type
    770771
    771772        stream = template.generate(**data)
    772773
     
    800801
    801802        try:
    802803            buffer = cStringIO()
     804            if method == 'xml':
     805                buffer.write('<?xml version="1.0" encoding="utf-8" ?>')
    803806            stream.render(method, doctype=doctype, out=buffer)
    804807            return buffer.getvalue().translate(_translate_nop,
    805808                                               _invalid_control_chars)

in reply to:  9 comment:10 by Emmanuel Blot, 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 Christian Boos, 15 years ago

Resolution: fixed
Status: reopenedclosed

Committed the patch above in [8618].

Please reopen if there's still a problem with this.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.