Skip to content

surrogateescape handler broken when encountering UnicodeEncodeError #256

@wence-

Description

@wence-

Consider:

$ python --version
2.7.9
from future.utils.surrogateescape import register_surrogateescape
register_surrogateescape()
print u'\u03b1'.encode("iso-8859-1", "surrogateescape")
=> future/utils/surrogateescape.pyc in replace_surrogate_encode(mystring)
     84         if not 0xD800 <= code <= 0xDCFF:
     85             # Not a surrogate. Fail with the original exception.
---> 86             raise exc
     87         # mybytes = [0xe0 | (code >> 12),
     88         #            0x80 | ((code >> 6) & 0x3f),

NameError: global name 'exc' is not defined

This is because replace_surrogate_encode tries to refer to the exception of its calling context, which obviously fails. A simple fix might be to pass that exception in as an argument.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions