summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-12-12 16:52:49 (GMT)
committerGitHub <noreply@github.com>2021-12-12 16:52:49 (GMT)
commit94483f1e3cec182fabe19268e579f63045bc984a (patch)
treedd22d834f0c0fb57fc167a4b7d83d0777aaf4ca2 /Lib
parent438817fdd5b731d486285d205bed2e78b655c0d6 (diff)
downloadcpython-94483f1e3cec182fabe19268e579f63045bc984a.zip
cpython-94483f1e3cec182fabe19268e579f63045bc984a.tar.gz
cpython-94483f1e3cec182fabe19268e579f63045bc984a.tar.bz2
bpo-46054: Fix parsing error when parsing non-utf8 characters in source files (GH-30068) (GH-30069)
(cherry picked from commit 4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_exceptions.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 9acb16c..cc0640d 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -2368,6 +2368,18 @@ class SyntaxErrorTests(unittest.TestCase):
finally:
unlink(TESTFN)
+ def test_non_utf8(self):
+ # Check non utf-8 characters
+ try:
+ with open(TESTFN, 'bw') as testfile:
+ testfile.write(b"\x89")
+ rc, out, err = script_helper.assert_python_failure('-Wd', '-X', 'utf8', TESTFN)
+ err = err.decode('utf-8').splitlines()
+
+ self.assertIn("SyntaxError: Non-UTF-8 code starting with '\\x89' in file", err[-1])
+ finally:
+ unlink(TESTFN)
+
def test_attributes_new_constructor(self):
args = ("bad.py", 1, 2, "abcdefg", 1, 100)
the_exception = SyntaxError("bad bad", args)