Issue #57 new

escape fails with unicode

Kapil Dua
created an issue

__M_writer(escape(h.HTML.td(h.escape(NAME), class_='ui-widget-content'))) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 1: ordinal not in range(128)

Comments (2)

  1. Mike Orr

    Markup (literal) is a subclass of Unicode, so it does have to convert str values to Unicode, and it uses the interpreter's default encoding ('ascii' unless you've set it differently in site.py/customize.py with sys.setdefaultencoding). If you have str values with non-ASCII characters, you should convert them to Unicode before passing them to escape().

    If you think there's still a bug, we'll need to see the actual value of 'name' and the part of the Mako template it occurs in, and the expected result. Leaving the ticket open for a few days for this.

  2. Kapil Dua reporter
    # coding: utf-8
    
    import webhelpers
    import sys
    from webhelpers.html import escape
    
    sys.setdefaultencoding = 'utf-8'
    
    
    print webhelpers.__version__
    print escape('Tōyō kanji299999')
    
  3. Log in to comment