Issue #9871: Prevent IDLE 3 crash when given byte stings

with invalid hex escape sequences, like b'\x0'.
(Original patch by Claudiu Popa.)
This commit is contained in:
Ned Deily 2011-09-14 14:49:14 -07:00
parent 962055d3c6
commit 79746426c4
4 changed files with 12 additions and 7 deletions

View file

@ -101,10 +101,10 @@ class ScriptBinding:
try:
# If successful, return the compiled code
return compile(source, filename, "exec")
except (SyntaxError, OverflowError) as value:
msg = value.msg or "<no detail available>"
lineno = value.lineno or 1
offset = value.offset or 0
except (SyntaxError, OverflowError, ValueError) as value:
msg = getattr(value, 'msg', '') or value or "<no detail available>"
lineno = getattr(value, 'lineno', '') or 1
offset = getattr(value, 'offset', '') or 0
if offset == 0:
lineno += 1 #mark end of offending line
pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)