Merge pull request #5271 from nicoddemus/lone-surrogate-jython-5256

Handle lone surrogate unicode character not being representable in Jython
This commit is contained in:
Anthony Sottile 2019-05-16 15:02:08 -07:00 committed by GitHub
commit d94b4b031f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1 @@
Handle internal error due to a lone surrogate unicode character not being representable in Jython.

View File

@ -998,7 +998,15 @@ def _get_line_with_reprcrash_message(config, rep, termwidth):
# u'😄' will result in a High Surrogate (U+D83D) character, which is
# rendered as u'<27>'; in this case we just strip that character out as it
# serves no purpose being rendered
msg = msg.rstrip(u"\uD83D")
try:
surrogate = six.unichr(0xD83D)
msg = msg.rstrip(surrogate)
except ValueError: # pragma: no cover
# Jython cannot represent this lone surrogate at all (#5256):
# ValueError: unichr() arg is a lone surrogate in range
# (0xD800, 0xDFFF) (Jython UTF-16 encoding)
# ignore this case as it shouldn't appear in the string anyway
pass
msg += ellipsis
line += sep + msg
return line