UTF-8 + HTML::Template + CGI::Fast

Dave Hodgkinson davehodg at gmail.com
Fri Dec 4 11:06:06 GMT 2009

On 4 Dec 2009, at 10:25, Andrew McGregor wrote:

> Hello,
> I'm hoping someone can help me with a UTF-8 problem.
> If a user enters latin-1 into a (CGI::Fast) form and submits, and the
> string is displayed (HTML::Template) as expected.
> If a user enters UTF-8 chars then the string displayed is corrupt, or
> looks like it has been double encoded.
> If I remove CGI::Fast then there is no problem.
> If I die $string before hitting HTML::Template then the UTF-8 string
> is displayed properly.
> I've patched HTML::Template to allow UTF-8 files.  I've tried passing
> in a fh opened as UTF-8 (segfault).
> I read somewhere that Perl doesn't cope well concatenating latin-1 and
> UTF-8 strings - could this be happening in HTML::Template?
> Or should I be posting somewhere else, HTML::Template list or CGI::Fast list?
> This is perl, v5.8.8 built for i386-linux-thread-multi

Consistency is the key. If you know Latin-1 is coming in from the
form, use Encode to convert it to UTF-8 and thus tell perl that's 
what it is. 

Oh, and "use utf8;" for good measure.

Apparently, a string isn't just a stream of octets :)

At least you don't have MySQL in the loop.

Dave Hodgkinson                                MSN: davehodg at hotmail.com
Site: http://www.davehodgkinson.com                  UK: +44 7768 490620
Blog: http://www.davehodgkinson.com/blog
Photos: http://www.flickr.com/photos/davehodg

More information about the london.pm mailing list