[Dancer-users] utf-8 issues

Puneet Kishor punk.kish at gmail.com
Fri Dec 23 22:42:29 CET 2011


On Dec 23, 2011, at 3:28 PM, Stefan Hornburg (Racke) wrote:

> On 12/23/2011 03:39 AM, Puneet Kishor wrote:
>> Fellow Dancers,
>> 
>> I am mystified by the following issue.
> > My Dancer-powered web site converts utf-8 encoded, plain text files formatted with Markdown into html.
> 
> How do you open these plain text files inside your Dancer application?
> If you use Perl's open function or File::Slurp, you have to tell them
> that your file is UTF-8. There is no way around that.
> 

That was it. Thanks. Here is what I had to do

	- open my $fh, "<", $full_path_to_page
	+ open my $fh, "<:encoding(UTF-8)", $full_path_to_page

Then I got an error in my customized Markdown.pm where `md5_hex` croaked, so I had to change that

	- my $key = md5_hex($tag);
	+ my $key = md5_hex(encode_utf8($tag));

It works now. So, I got lulled by the documentation that says that I all I have to do is to set the `charset utf-8` in config.yml, and Dancer would take care of everything.

Another interesting thing -- before I made the above changes, as I noted in my earlier email, I just wrote out the output to a file on disk before sending it back to the browser. The file written to the disk has the text rendered just fine. Any explanations why?


In any case, all's well now.

--
Puneet Kishor


More information about the Dancer-users mailing list