[pypy-commit] pypy stdlib-3.2.5: cpython issue12983: bytes literals with invalid \x escape now raise a
pjenvey
noreply at buildbot.pypy.org
Wed Apr 9 01:32:29 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: stdlib-3.2.5
Changeset: r70493:f8d19753723f
Date: 2014-04-08 16:20 -0700
http://bitbucket.org/pypy/pypy/changeset/f8d19753723f/
Log: cpython issue12983: bytes literals with invalid \x escape now raise
a SyntaxError
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1122,9 +1122,10 @@
sub_strings_w = [parsestring.parsestr(space, encoding, s.value)
for s in atom_node.children]
except error.OperationError, e:
- if not e.match(space, space.w_UnicodeError):
+ if not (e.match(space, space.w_UnicodeError) or
+ e.match(space, space.w_ValueError)):
raise
- # UnicodeError in literal: turn into SyntaxError
+ # Unicode/ValueError in literal: turn into SyntaxError
self.error(e.errorstr(space), atom_node)
sub_strings_w = [] # please annotator
# Implement implicit string concatenation.
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -1307,3 +1307,7 @@
if1, if2 = comps[0].ifs
assert isinstance(if1, ast.Name)
assert isinstance(if2, ast.Name)
+
+ def test_cpython_issue12983(self):
+ raises(SyntaxError, self.get_ast, r"""b'\x'""")
+ raises(SyntaxError, self.get_ast, r"""b'\x0'""")
diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -191,7 +191,8 @@
ps += 2
else:
if errors == 'strict':
- raise_app_valueerror(space, 'invalid \\x escape')
+ raise_app_valueerror(
+ space, "invalid \\x escape at position %d" % (ps - 2))
elif errors == 'replace':
builder.append('?')
elif errors == 'ignore':
More information about the pypy-commit
mailing list