mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Forward port MvL's fix in 43227:
Fix crash when a Unicode string containing an encoding declaration is compile()d. Fixes #1115379.
This commit is contained in:
		
							parent
							
								
									4d073bb9a1
								
							
						
					
					
						commit
						e98ccf6690
					
				
					 3 changed files with 11 additions and 0 deletions
				
			
		|  | @ -284,6 +284,10 @@ def f(): | ||||||
|         f1, f2 = f() |         f1, f2 = f() | ||||||
|         self.assertNotEqual(id(f1.func_code), id(f2.func_code)) |         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): |     def test_subscripts(self): | ||||||
|         # SF bug 1448804 |         # SF bug 1448804 | ||||||
|         # Class to make testing subscript results easy |         # Class to make testing subscript results easy | ||||||
|  |  | ||||||
|  | @ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1? | ||||||
| Core and builtins | 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 | - Previously, Python code had no easy way to access the contents of a | ||||||
|   cell object. Now, a ``cell_contents`` attribute has been added |   cell object. Now, a ``cell_contents`` attribute has been added | ||||||
|   (closes patch #1170323). |   (closes patch #1170323). | ||||||
|  |  | ||||||
|  | @ -191,6 +191,10 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename, | ||||||
| 
 | 
 | ||||||
|     if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) { |     if (flags && flags->cf_flags & PyCF_SOURCE_IS_UTF8) { | ||||||
|         c.c_encoding = "utf-8"; |         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) { |     } else if (TYPE(n) == encoding_decl) { | ||||||
|         c.c_encoding = STR(n); |         c.c_encoding = STR(n); | ||||||
|         n = CHILD(n, 0); |         n = CHILD(n, 0); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Neal Norwitz
						Neal Norwitz