diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-17 01:13:37 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-17 01:13:37 (GMT) |
commit | 6baded49d0abf07f141dae489c6a010af1b1e209 (patch) | |
tree | 49ec83c86cb48d362b662dbe99b5cd3d2b762027 /Lib | |
parent | f155f1f4cef42e26809e3512634e4ed083b7965c (diff) | |
download | cpython-6baded49d0abf07f141dae489c6a010af1b1e209.zip cpython-6baded49d0abf07f141dae489c6a010af1b1e209.tar.gz cpython-6baded49d0abf07f141dae489c6a010af1b1e209.tar.bz2 |
Issue #6697: Fix a crash if code of "python -c code" contains surrogates
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_sys.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index a9f3f5e..abbd759 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -449,6 +449,24 @@ class SysModuleTest(unittest.TestCase): self.assertRaises(TypeError, sys.intern, S("abc")) + def test_main_invalid_unicode(self): + import locale + non_decodable = b"\xff" + encoding = locale.getpreferredencoding() + try: + non_decodable.decode(encoding) + except UnicodeDecodeError: + pass + else: + self.skipTest('%r is decodable with encoding %s' + % (non_decodable, encoding)) + code = b'print("' + non_decodable + b'")' + p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + self.assertEqual(p.returncode, 1) + self.assert_(stderr.startswith(b"UnicodeEncodeError: " + b"'utf-8' codec can't encode character '\\udcff' in " + b"position 7: surrogates not allowed"), stderr) def test_sys_flags(self): self.assertTrue(sys.flags) |