Commit 5cdb7ba3 authored by Stefan Behnel's avatar Stefan Behnel

reject invalid hex/unicode escape sequences instead of letting them crash the compiler

parent 7f45b0b7
......@@ -782,13 +782,19 @@ def p_string_literal(s, kind_override=None):
elif c == u'\n':
pass
elif c == u'x':
if len(systr) == 4:
chars.append_charval( int(systr[2:], 16) )
else:
s.error("Invalid hex escape '%s'" % systr, pos=s.position())
elif c in u'Uu':
if kind in ('u', ''):
if len(systr) in (6,10):
chrval = int(systr[2:], 16)
if chrval > 1114111: # sys.maxunicode:
s.error("Invalid unicode escape '%s'" % systr,
pos = pos)
else:
s.error("Invalid unicode escape '%s'" % systr, pos=s.position())
else:
# unicode escapes in plain byte strings are not unescaped
chrval = None
......
'\x'
_ERRORS = '''
2:1: Invalid hex escape '\x'
'''
'\x1'
_ERRORS = '''
2:1: Invalid hex escape '\x'
'''
u'\uXYZ'
_ERRORS = '''
2:2: Invalid unicode escape '\u'
'''
u'\u'
_ERRORS = '''
2:1: Invalid unicode escape '\u'
'''
u'\u12'
_ERRORS = '''
2:1: Invalid unicode escape '\u'
'''
......@@ -125,6 +125,13 @@ __doc__ = ur"""
>>> len(uresc)
9
>>> bytes_uescape
b'\\u1234\\U12345678\\u\\u1\\u12\\uX'
>>> bytes_uescape == b'\\u1234\\U12345678\\u\\u1\\u12\\uX'
True
>>> len(bytes_uescape)
28
>>> newlines == "Aaa\n"
True
......@@ -165,6 +172,8 @@ sresc = r'\12\'\"\\'
bresc = br'\12\'\"\\'
uresc = ur'\12\'\"\\'
bytes_uescape = b'\u1234\U12345678\u\u1\u12\uX'
newlines = "Aaa\n"
# T640, long literals with escapes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment