Commit 11f0b41e authored by Florent Xicluna's avatar Florent Xicluna

Issue #14990: tokenize: correctly fail with SyntaxError on invalid encoding declaration.

parent 9235b254
...@@ -674,6 +674,10 @@ class TestTokenizerAdheresToPep0263(TestCase): ...@@ -674,6 +674,10 @@ class TestTokenizerAdheresToPep0263(TestCase):
f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt' f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
self.assertTrue(self._testFile(f)) self.assertTrue(self._testFile(f))
def test_bad_coding_cookie(self):
self.assertRaises(SyntaxError, self._testFile, 'bad_coding.py')
self.assertRaises(SyntaxError, self._testFile, 'bad_coding2.py')
class Test_Tokenize(TestCase): class Test_Tokenize(TestCase):
......
...@@ -310,7 +310,7 @@ def detect_encoding(readline): ...@@ -310,7 +310,7 @@ def detect_encoding(readline):
raise SyntaxError("unknown encoding: " + encoding) raise SyntaxError("unknown encoding: " + encoding)
if bom_found: if bom_found:
if codec.name != 'utf-8': if encoding != 'utf-8':
# This behaviour mimics the Python interpreter # This behaviour mimics the Python interpreter
raise SyntaxError('encoding problem: utf-8') raise SyntaxError('encoding problem: utf-8')
encoding += '-sig' encoding += '-sig'
......
...@@ -87,6 +87,9 @@ Core and Builtins ...@@ -87,6 +87,9 @@ Core and Builtins
Library Library
------- -------
- Issue #14990: Correctly fail with SyntaxError on invalid encoding
declaration.
- Issue #15247: FileIO now raises an error when given a file descriptor - Issue #15247: FileIO now raises an error when given a file descriptor
pointing to a directory. pointing to a directory.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment