Erlang/OTP Forums

Author Message

<  Erlang Web mailing list  ~  [Erlangweb-users] UTF-8 fixes

Guest
Posted: Fri Apr 09, 2010 10:11 pm Reply with quote
Guest
Hello,

I found a few bugs concerning utf8 handling in dtl templates and in forms.
Value stored in database are stored with large integer value of characters and those
would end up into the template result and make xmerl complain and bug.

I modified erlydtl_compiler:format to correct this:
diff -r old/lib/erlydtl-0.5.3/src/erlydtl/erlydtl_compiler.erl new/lib/erlydtl-0.5.3/src/erlydtl/erlydtl_compiler.erl
548c548,552
< auto_escape(format_number_ast(Ast), Context).
---
> Tmp = format_number_ast(Ast),
> %% Value is a list of Unicode codepoints. We need to convert that
> %% to UTF-8.
> Tmp2 = erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(utf32_to_utf8), [Tmp]),
> auto_escape(Tmp2, Context).

the "utf32_to_utf8" function I put in erlydtl_filters ; but I'm sure there
must be a more appropriate place for it. It was a quick hack.
diff -r old/lib/erlydtl-0.5.3/src/erlydtl/erlydtl_filters.erl new/lib/erlydtl-0.5.3/src/erlydtl/erlydtl_filters.erl
192a193,199
> utf32_to_utf8(Input) when is_list(Input) ->
> % Convert utf32 strings into utf8
> {ok, UTF8} = utf8:to_binary(Input),
> binary_to_list(UTF8);
> utf32_to_utf8(Input) ->
> Input.
>

I also found another problem with forms. wpart forms would retrieve the large integer
character and bug.
Here's what I did to fix it:
diff -r old/lib/wparts-1.4/src/wpart_derived.erl new/lib/wparts-1.4/src/wpart_derived.erl
135c135
< Input = Module:build_html_tag(LName, Params, find(LName, Defaults)),
---
> Input = Module:build_html_tag(LName, Params, erlydtl_filters:utf32_to_utf8(find(LName, Defaults))),


I hope it'll helps.

Regards.

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Erlangweb-users mailing list
Erlangweb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlangweb-users
http://www.erlang-web.org/
Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum