summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_compile.py4
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/ast.c4
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 1d47f91..72c4f7e 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -284,6 +284,10 @@ if 1:
f1, f2 = f()
self.assertNotEqual(id(f1.func_code), id(f2.func_code))
+ def test_unicode_encoding(self):
+ code = u"# -*- coding: utf-8 -*-\npass\n"
+ self.assertRaises(SyntaxError, compile, code, "tmp", "exec")
+
def test_subscripts(self):
# SF bug 1448804
# Class to make testing subscript results easy
diff --git a/Misc/NEWS b/Misc/NEWS
index 400504d..f41f237 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
Core and builtins
-----------------
+- Bug #1115379: Compiling a Unicode string with an encoding declaration
+ now gives a SyntaxError.
+
- Previously, Python code had no easy way to access the contents of a
cell object. Now, a ``cell_contents`` attribute has been added
(closes patch #1170323).
diff --git a/Python/ast.c b/Python/ast.c
index 3c339f0..30275a6 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -191,6 +191,10 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) {
c.c_encoding = "utf-8";
+ if (TYPE(n) == encoding_decl) {
+ ast_error(n, "encoding declaration in Unicode string");
+ goto error;
+ }
} else if (TYPE(n) == encoding_decl) {
c.c_encoding = STR(n);
n = CHILD(n, 0);