[htmltmpl] Patch to encode iso-8859-1 using HTML::Entities
Brought to you by:
samtregar
From: Dave W. S. <dw...@da...> - 2004-10-19 04:18:25
|
We ran headlong into the need to add iso-8859-1 (Latin1) support to a = large webapp that used over a hundred templates. Rather than tracking down the many places where we stuffed parameters, then modify them to use HTML::Entities (and remove "ESCAPE=3DHTML"), I took the "simplest thing = that could possibly work" path, and added an 'encode_entities' option to = new(). When true, it causes 7-bit unclean characters to be escaped via HTML::Entities::encode_entities() when "ESCAPE=3DHTML" is used. With the patch, getting most of the way to Latin1 support was a simple = as adding my $template =3D HTML::Template->new( filename =3D> $template, global_vars =3D> 1, cache =3D> 1, + encode_entities =3D> 1, ); The performance hit (for the encode_entities =3D> 1 case) is < 1% for = our app, as measured via our unit test suite.=20 The patch for HTML::Template 2.7, including doc changes and unit tests, = is http://www.davewsmith.com/code/HTML-Template-2_7-encode.diff To maintain backward compatibility for people who expect single-quotes = to be escaped (e.g., for existing unit tests), single quotes are escaped = either way. Dave |