[Dancer-users] utf-8 issues

Stefan Hornburg (Racke) racke at linuxia.de
Fri Dec 23 22:50:11 CET 2011


On 12/23/2011 10:42 PM, Puneet Kishor wrote:
>
> 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?
>

File systems don't care about the file contents, so if you read something from there it's unfortunately our
task to know about the encoding.

Regards
	Racke


-- 
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team



More information about the Dancer-users mailing list