Have you tried using utf8 as the encoding? You will get far more millage out of utf8 than using entities.

regards,
Mathew

Alex Teslik wrote:
Hello,

  I'm developing an app where there are some strings that have HTML entities
in them, such as:

This is a "Tést"

These strings need to go into a template that is displayed in the iso-8859-1
character set. These strings need to be html escaped so that the quotes don't
break things. When I put it in a template:

<tmpl_var name="sentence" escape="html">

I get:

This is a &quot;&amp;#233;st&quot;

Doh. The entity got squashed.

So the easy way out is "just decode the entity before dropping it in the
template"... but if the decoded entity cannot be displayed in iso-8859-1 when
it is decoded, as is the case with a Chinese character like &#25105;, than I'm
out of luck and must pass the entity through to the template. But then I can
no longer do all my escaping in the template.

So I propose that the HTML::Template escaping does not squash HTML entities.
Something like (quick off the cuff):

sub entity_safe_escape {
   my $t=shift;

   $t=~s/&#(\d\d\d+);/ESCAPE_UNICODE_$1/g;
   $t=~s/&/ESCAPE_AMP/g;
$t=~s/"/&quot;/g;
   $t=~s/</&lt;/g;
   $t=~s/>/&gt;/g;
$t=~s/ESCAPE_AMP/&amp;/g;
   $t=~s/ESCAPE_UNICODE_(\d\d\d+)/&#$1;/g;
return($t);
}

How do others typically get around this problem?

Thanks,
Alex

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to