[Zope-dev] Content Type Meta tag stripping in zope.pagetemplate

Miano Njoka mianonjoka at gmail.com
Wed Feb 22 15:28:56 UTC 2012


Hello all,

I'm a fairly new zope developer, came across a "bug" in my application
that <meta http-equiv="content-type" content="text/html;charset=UTF-8"
/> tags were being stripped out from ZPT templates. Is there a reason
for this? This is done in the _prepare_html function of
zope.pagetemplate.pagetemplatefile.PageTemplateFile. My application
produces XHTML that contains non-ASCII characters that is then used by
other applications so it needs to have the content type set on the
document itself in addition to the HTTP headers.

Secondly, finding and stripping of the meta tag is done using a regular
expression so simply changing the order of the attributes on the
<meta> tag would make the reg-exp not match.

Attached is a patch that uses HTMLParser to find the content type meta
tag instead of a regex. It stops parsing the html as soon as it
encounters the required meta tag.

Miano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: meta_content_type_tag.patch
Type: text/x-patch
Size: 3808 bytes
Desc: not available
URL: <http://mail.zope.org/pipermail/zope-dev/attachments/20120222/bd332dfa/attachment.bin>


More information about the Zope-Dev mailing list