Commits

Martin von Löwis committed 4d80607

Change SystemError into SyntaxError, when a Unicode string
containing an encoding declaration is compile()d. Fixes
#1115379.

Comments (0)

Files changed (3)

Lib/test/test_compile.py

         f1, f2 = f()
         self.assertNotEqual(id(f1.func_code), id(f2.func_code))
 
+    def test_unicode_encoding(self):
+        # SF bug 1115379
+        self.assertRaises(SyntaxError, compile, u"# -*- coding: utf-8 -*-\npass\n", "tmp", "exec")
+
 def test_main():
     test_support.run_unittest(TestSpecifics)
 
 Core and builtins
 -----------------
 
+- Bug #1115379: Compiling a Unicode string with an encoding declaration
+  now gives a SyntaxError.
+
 - Fix missing check on whether the PendingDeprecationWarning for string
   exceptions was re-raised as an actual PendingDeprecationWarning when
   'warnings' is set to a filter action of "error"
 		return NULL;
 	if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) {
 		sc.c_encoding = "utf-8";
+		if (TYPE(n) == encoding_decl) {
+			com_error(&sc, PyExc_SyntaxError, 
+				  "encoding declaration in Unicode string");
+			co = NULL;
+			goto exit;
+		}
 	} else if (TYPE(n) == encoding_decl) {
 		sc.c_encoding = STR(n);
 		n = CHILD(n, 0);
 		PyErr_SetString(PyExc_SystemError, "lost syntax error");
 	}
  exit:
-	if (base == NULL) {
+	if (base == NULL && sc.c_symtable != NULL) {
 		PySymtable_Free(sc.c_symtable);
 		sc.c_symtable = NULL;
 	}