Support unicode characters in printable-function #66

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@jmagnusson

repr function returns str, which is not liked by jinja2 if non-ascii characters occur.

@jmagnusson jmagnusson Support unicode characters for printables
`repr` function returns `str`, which is not liked by `jinja2` if non-ascii characters occur.
daa2aed
@mgood mgood added a commit that closed this pull request Feb 2, 2014
@mgood `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.

Fixes #66
82295aa
@mgood mgood closed this in 82295aa Feb 2, 2014
Owner
mgood commented Feb 2, 2014

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? :)

@jmagnusson jmagnusson deleted the jmagnusson:unicode-repr branch Jun 23, 2014

@mgood what about a new release with your fix?

@mgood, any chance to get this released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment