diff options
author | Eric Smith <eric@trueblade.com> | 2010-02-24 15:53:54 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2010-02-24 15:53:54 (GMT) |
commit | f2387da424269d2b124a009c6778ebd2ed5abd50 (patch) | |
tree | 10947458bf40bfe0a15151656dffcc1c75764ea6 /Lib/test/test_exceptions.py | |
parent | b61a04d72aab94a427513099d09edab0e7a9c90e (diff) | |
download | cpython-f2387da424269d2b124a009c6778ebd2ed5abd50.zip cpython-f2387da424269d2b124a009c6778ebd2ed5abd50.tar.gz cpython-f2387da424269d2b124a009c6778ebd2ed5abd50.tar.bz2 |
Merged revisions 78420 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r78420 | eric.smith | 2010-02-24 10:42:29 -0500 (Wed, 24 Feb 2010) | 9 lines
Merged revisions 78418 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78418 | eric.smith | 2010-02-24 09:15:36 -0500 (Wed, 24 Feb 2010) | 1 line
Issue #7309: Unchecked pointer access when converting UnicodeEncodeError, UnicodeDecodeError, and UnicodeTranslateError to strings.
........
................
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 404b5d1..6aa8102 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -568,6 +568,42 @@ class ExceptionTests(unittest.TestCase): pass self.assertEquals(e, (None, None, None)) + def testUnicodeChangeAttributes(self): + # See issue 7309. This was a crasher. + + u = UnicodeEncodeError('baz', 'xxxxx', 1, 5, 'foo') + self.assertEqual(str(u), "'baz' codec can't encode characters in position 1-4: foo") + u.end = 2 + self.assertEqual(str(u), "'baz' codec can't encode character '\\x78' in position 1: foo") + u.end = 5 + u.reason = 0x345345345345345345 + self.assertEqual(str(u), "'baz' codec can't encode characters in position 1-4: 965230951443685724997") + u.encoding = 4000 + self.assertEqual(str(u), "'4000' codec can't encode characters in position 1-4: 965230951443685724997") + u.start = 1000 + self.assertEqual(str(u), "'4000' codec can't encode characters in position 1000-4: 965230951443685724997") + + u = UnicodeDecodeError('baz', b'xxxxx', 1, 5, 'foo') + self.assertEqual(str(u), "'baz' codec can't decode bytes in position 1-4: foo") + u.end = 2 + self.assertEqual(str(u), "'baz' codec can't decode byte 0x78 in position 1: foo") + u.end = 5 + u.reason = 0x345345345345345345 + self.assertEqual(str(u), "'baz' codec can't decode bytes in position 1-4: 965230951443685724997") + u.encoding = 4000 + self.assertEqual(str(u), "'4000' codec can't decode bytes in position 1-4: 965230951443685724997") + u.start = 1000 + self.assertEqual(str(u), "'4000' codec can't decode bytes in position 1000-4: 965230951443685724997") + + u = UnicodeTranslateError('xxxx', 1, 5, 'foo') + self.assertEqual(str(u), "can't translate characters in position 1-4: foo") + u.end = 2 + self.assertEqual(str(u), "can't translate character '\\x78' in position 1: foo") + u.end = 5 + u.reason = 0x345345345345345345 + self.assertEqual(str(u), "can't translate characters in position 1-4: 965230951443685724997") + u.start = 1000 + self.assertEqual(str(u), "can't translate characters in position 1000-4: 965230951443685724997") def test_badisinstance(self): # Bug #2542: if issubclass(e, MyException) raises an exception, |