Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Lib/test/test_parser_utf7_r.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
import py_compile
import os

class TestParserUTF7Newline(unittest.TestCase):
def test_utf7_r_after_coding_cookie(self):
# This reproduced a SystemError in string_parser.c
# where \r introduced by codec caused the lexer to
# produce a broken token.
filename = 'test_utf7_r.py'
if os.path.exists(filename):
os.remove(filename)
self.addCleanup(os.remove, filename)

# '+AA0-' is UTF-7 for '\r'.
# The '-' is optional if followed by non-base64.
with open(filename, 'wb') as f:
f.write(b"#coding=u7+AA0''")

try:
py_compile.compile(filename, doraise=True)
except SyntaxError:
# We don't care if it's a syntax error (it shouldn't be,
# but that's not the bug), we care that it doesn't
# raise SystemError.
pass
except SystemError as e:
self.fail(f"SystemError raised: {e}")

if __name__ == "__main__":
unittest.main()
Loading
Loading