]> granicus.if.org Git - python/commitdiff
Issue #14990: tokenize: correctly fail with SyntaxError on invalid encoding declaration.
authorFlorent Xicluna <florent.xicluna@gmail.com>
Sat, 7 Jul 2012 10:13:35 +0000 (12:13 +0200)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Sat, 7 Jul 2012 10:13:35 +0000 (12:13 +0200)
Lib/test/test_tokenize.py
Lib/tokenize.py
Misc/NEWS

index 63d084df731babedc2a0c057c26f9ba717c85fa8..b6a9ca1e16821263432465cbb2cc48bf95be8e45 100644 (file)
@@ -674,6 +674,10 @@ class TestTokenizerAdheresToPep0263(TestCase):
         f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
         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):
 
index f283c6dd7f9e486a79e573e91f715264748064f2..59081d3579082dcf38b26a1181d8a805e9657c8f 100644 (file)
@@ -310,7 +310,7 @@ def detect_encoding(readline):
             raise SyntaxError("unknown encoding: " + encoding)
 
         if bom_found:
-            if codec.name != 'utf-8':
+            if encoding != 'utf-8':
                 # This behaviour mimics the Python interpreter
                 raise SyntaxError('encoding problem: utf-8')
             encoding += '-sig'
index 699b4fb18b98adcd7ce82e8145bc42aec10103af..92131b4eb64234123ad1d10a08915b8b2223d4b6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -87,6 +87,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14990: Correctly fail with SyntaxError on invalid encoding
+  declaration.
+
 - Issue #15247: FileIO now raises an error when given a file descriptor
   pointing to a directory.