Skip to content

Commit f4373d1

Browse files
committed
Handle lone surrogate unicode character not being representable in Jython
No tests for this because we don't test with Jython currently. Fix #5256
1 parent c8f7e50 commit f4373d1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

changelog/5256.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle internal error due to a lone surrogate unicode character not being representable in Jython.

src/_pytest/terminal.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,15 @@ def _get_line_with_reprcrash_message(config, rep, termwidth):
998998
# u'😄' will result in a High Surrogate (U+D83D) character, which is
999999
# rendered as u'�'; in this case we just strip that character out as it
10001000
# serves no purpose being rendered
1001-
msg = msg.rstrip(u"\uD83D")
1001+
try:
1002+
surrogate = six.unichr(0xD83D)
1003+
msg = msg.rstrip(surrogate)
1004+
except ValueError: # noqa
1005+
# Jython cannot represent this lone surrogate at all (#5256):
1006+
# ValueError: unichr() arg is a lone surrogate in range
1007+
# (0xD800, 0xDFFF) (Jython UTF-16 encoding)
1008+
# ignore this case as it shouldn't appear in the string anyway
1009+
pass
10021010
msg += ellipsis
10031011
line += sep + msg
10041012
return line

0 commit comments

Comments
 (0)