mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Fix issue 1661: Flags argument silently ignored in re functions with compiled regexes.
This commit is contained in:
		
							parent
							
								
									0f5e7bf304
								
							
						
					
					
						commit
						80016c9555
					
				
					 2 changed files with 10 additions and 0 deletions
				
			
		|  | @ -224,6 +224,8 @@ def _compile(*key): | ||||||
|         return p |         return p | ||||||
|     pattern, flags = key |     pattern, flags = key | ||||||
|     if isinstance(pattern, _pattern_type): |     if isinstance(pattern, _pattern_type): | ||||||
|  |         if flags: | ||||||
|  |             raise ValueError('Cannot process flags argument with a compiled pattern') | ||||||
|         return pattern |         return pattern | ||||||
|     if not sre_compile.isstring(pattern): |     if not sre_compile.isstring(pattern): | ||||||
|         raise TypeError, "first argument must be string or compiled pattern" |         raise TypeError, "first argument must be string or compiled pattern" | ||||||
|  |  | ||||||
|  | @ -108,6 +108,14 @@ def test_bug_1140(self): | ||||||
|                 self.assertEqual(z, y) |                 self.assertEqual(z, y) | ||||||
|                 self.assertEqual(type(z), type(y)) |                 self.assertEqual(type(z), type(y)) | ||||||
| 
 | 
 | ||||||
|  |     def test_bug_1661(self): | ||||||
|  |         # Verify that flags do not get silently ignored with compiled patterns | ||||||
|  |         pattern = re.compile('.') | ||||||
|  |         self.assertRaises(ValueError, re.match, pattern, 'A', re.I) | ||||||
|  |         self.assertRaises(ValueError, re.search, pattern, 'A', re.I) | ||||||
|  |         self.assertRaises(ValueError, re.findall, pattern, 'A', re.I) | ||||||
|  |         self.assertRaises(ValueError, re.compile, pattern, re.I) | ||||||
|  | 
 | ||||||
|     def test_sub_template_numeric_escape(self): |     def test_sub_template_numeric_escape(self): | ||||||
|         # bug 776311 and friends |         # bug 776311 and friends | ||||||
|         self.assertEqual(re.sub('x', r'\0', 'x'), '\0') |         self.assertEqual(re.sub('x', r'\0', 'x'), '\0') | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger