Author: Armin Rigo <[email protected]>
Branch:
Changeset: r55568:287e0257dfd3
Date: 2012-06-11 11:03 +0200
http://bitbucket.org/pypy/pypy/changeset/287e0257dfd3/
Log: Test and fix for issue1159: the logic in parsestring.py was subtly
broken by 6f5ea64c8b8d. Fix it by reverting the use of
append_slice().
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
@@ -1105,6 +1105,17 @@
assert isinstance(s, ast.Str)
assert space.eq_w(s.s, space.wrap(sentence))
+ def test_string_bug(self):
+ space = self.space
+ source = '# -*- encoding: utf8 -*-\nstuff = "x \xc3\xa9 \\n"\n'
+ info = pyparse.CompileInfo("<test>", "exec")
+ tree = self.parser.parse_source(source, info)
+ assert info.encoding == "utf8"
+ s = ast_from_node(space, tree, info).body[0].value
+ assert isinstance(s, ast.Str)
+ expected = ['x', ' ', chr(0xc3), chr(0xa9), ' ', '\n']
+ assert space.eq_w(s.s, space.wrap(''.join(expected)))
+
def test_number(self):
def get_num(s):
node = self.get_first_expr(s)
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
@@ -129,19 +129,18 @@
builder = StringBuilder(len(s))
ps = 0
end = len(s)
- while 1:
- ps2 = ps
- while ps < end and s[ps] != '\\':
+ while ps < end:
+ if s[ps] != '\\':
+ # note that the C code has a label here.
+ # the logic is the same.
if recode_encoding and ord(s[ps]) & 0x80:
w, ps = decode_utf8(space, s, ps, end, recode_encoding)
+ # Append bytes to output buffer.
builder.append(w)
- ps2 = ps
else:
+ builder.append(s[ps])
ps += 1
- if ps > ps2:
- builder.append_slice(s, ps2, ps)
- if ps == end:
- break
+ continue
ps += 1
if ps == end:
diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py
b/pypy/interpreter/pyparser/test/test_parsestring.py
--- a/pypy/interpreter/pyparser/test/test_parsestring.py
+++ b/pypy/interpreter/pyparser/test/test_parsestring.py
@@ -84,3 +84,10 @@
s = '"""' + '\\' + '\n"""'
w_ret = parsestring.parsestr(space, None, s)
assert space.str_w(w_ret) == ''
+
+ def test_bug1(self):
+ space = self.space
+ expected = ['x', ' ', chr(0xc3), chr(0xa9), ' ', '\n']
+ input = ["'", 'x', ' ', chr(0xc3), chr(0xa9), ' ', chr(92), 'n', "'"]
+ w_ret = parsestring.parsestr(space, 'utf8', ''.join(input))
+ assert space.str_w(w_ret) == ''.join(expected)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit