Author: Philip Jenvey <[email protected]>
Branch: stdlib-2.7.6
Changeset: r69591:a4e6cfbf8f11
Date: 2014-03-01 17:41 -0800
http://bitbucket.org/pypy/pypy/changeset/a4e6cfbf8f11/
Log: cpython issue13612: avoid crashing in the case of multibyte
encodings. also, fix a thinko in UnknownEncodingHandlerData_callback
diff --git a/pypy/module/pyexpat/interp_pyexpat.py
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -336,7 +336,7 @@
try:
parser.UnknownEncodingHandler(space, name, info)
except OperationError, e:
- if parser._exc_info:
+ if not parser._exc_info:
parser._exc_info = e
XML_StopParser(parser.itself, XML_FALSE)
result = 0
@@ -584,6 +584,10 @@
space.wrap(self.all_chars), "decode",
space.wrap(name), space.wrap("replace")))
+ if len(translationmap) != 256:
+ raise oefmt(space.w_ValueError,
+ "multi-byte encodings are not supported")
+
for i in range(256):
c = translationmap[i]
if c == u'\ufffd':
diff --git a/pypy/module/pyexpat/test/test_parser.py
b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -2,7 +2,7 @@
from pytest import skip
class AppTestPyexpat:
- spaceconfig = dict(usemodules=['pyexpat'])
+ spaceconfig = dict(usemodules=['pyexpat', '_multibytecodec'])
def teardown_class(cls):
global_storage.clear()
@@ -109,6 +109,13 @@
p.CharacterDataHandler = gotText
p.Parse(xml)
+ def test_mbcs(self):
+ xml = "<?xml version='1.0' encoding='gbk'?><p/>"
+ import pyexpat
+ p = pyexpat.ParserCreate()
+ exc = raises(ValueError, p.Parse, xml)
+ assert str(exc.value) == "multi-byte encodings are not supported"
+
def test_decode_error(self):
xml = '<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>'
import pyexpat
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit