repr function returns str, which is not liked by jinja2 if non-ascii characters occur.
Support unicode characters for printables
`repr` function returns `str`, which is not liked by `jinja2` if non-ascii characters occur.
`printable` filter should replace non-ascii bytes
In Python 2, when repr() returns bytes, replace any non-ascii bytes
with the unicode ? character to ensure that the result is printable.
Thanks for the patch, but I've committed a different fix that uses Python's encoding error handling to replace any non-ASCII charters with the � character, which is similar to what would happen if you tried to print that value in the Python console.
I also didn't want to depend on importing Flask's internal _compat module, which given the _ prefix is probably not intended as part of the public API.
I would also recommend looking into the __repr__ method that returned this non-ASCII value, since it would be better if it escaped its result instead.
I commonly see people use something like this in __repr__:
return 'Foo(%s)' % self.value
However, it's better to use the %r substitution instead:
return 'Foo(%r)' % self.value
Fair enough. Would it be possible to see a new release with this fix soon? :)
@mgood what about a new release with your fix?
@mgood, any chance to get this released?