[Python-checkins] r43243 - in python/trunk: Lib/test/test_compile.py Misc/NEWS Python/ast.c
neal.norwitz
python-checkins at python.org
Thu Mar 23 06:39:48 CET 2006
Author: neal.norwitz
Date: Thu Mar 23 06:39:47 2006
New Revision: 43243
Modified:
python/trunk/Lib/test/test_compile.py
python/trunk/Misc/NEWS
python/trunk/Python/ast.c
Log:
Forward port MvL's fix in 43227:
Fix crash when a Unicode string containing an encoding declaration is
compile()d. Fixes #1115379.
Modified: python/trunk/Lib/test/test_compile.py
==============================================================================
--- python/trunk/Lib/test/test_compile.py (original)
+++ python/trunk/Lib/test/test_compile.py Thu Mar 23 06:39:47 2006
@@ -284,6 +284,10 @@
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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Mar 23 06:39:47 2006
@@ -12,6 +12,9 @@
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).
Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c (original)
+++ python/trunk/Python/ast.c Thu Mar 23 06:39:47 2006
@@ -191,6 +191,10 @@
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);
More information about the Python-checkins
mailing list