It seems I discovered an issue with handling Unicode strings in the
WebHelpers version 0.2.1 (Pylons 0.9.2) which causes problems with
methods such as h.text_field().

When testing with Japanese and other "exotic" characters, I ended up
with error messages similar to:

> Error(UnicodeEncodeError): 'ascii' codec can't encode characters in position 
> 0-7: ordinal not in range(128)

I finally tracked down the cause of this problem to
webhelpers/rails/tags.py [1], around line 77, which reads:

> optionlist = ['%s="%s"' % (x, html_escape(str(y))) for x,y in 
> cleaned_options.iteritems()]

where it should:

> optionlist = ['%s="%s"' % (x, html_escape(y)) for x,y in 
> cleaned_options.iteritems()]

html_escape() is located in webhelpers.util package [2], and it takes
care of a) stringifying all non-string objects to strings and b)
"properly" encoding Unicode strings into ASCII representations itself
(basically, via "<unicode string>.encode('ascii',
'xmlcharrefreplace')").

The str(y) call in tags.py's list comprehension is not so clever, and
will break WebHelpers functions such as h.text_field() when called with
Unicode strings as values. I checked whether the faulty line in tags.py
has been corrected after 0.9.2 but it is still included in the trunk.

Michael

Note: I admit that I'm not sure whether the "issue" described above is
rather a feature, and not a bug. :-)

[1] http://pylonshq.com/svn/WebHelpers/trunk/webhelpers/rails/tags.py
[2] http://pylonshq.com/svn/WebHelpers/trunk/webhelpers/util.py


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to