mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	Issue #19545: Avoid chained exceptions while passing stray % to
time.strptime(). Initial patch by Claudiu Popa.
This commit is contained in:
		
							parent
							
								
									44d2429a25
								
							
						
					
					
						commit
						cdac302af3
					
				
					 4 changed files with 12 additions and 1 deletions
				
			
		| 
						 | 
					@ -329,7 +329,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
 | 
				
			||||||
                                    (bad_directive, format)) from None
 | 
					                                    (bad_directive, format)) from None
 | 
				
			||||||
            # IndexError only occurs when the format string is "%"
 | 
					            # IndexError only occurs when the format string is "%"
 | 
				
			||||||
            except IndexError:
 | 
					            except IndexError:
 | 
				
			||||||
                raise ValueError("stray %% in format '%s'" % format)
 | 
					                raise ValueError("stray %% in format '%s'" % format) from None
 | 
				
			||||||
            _regex_cache[format] = format_regex
 | 
					            _regex_cache[format] = format_regex
 | 
				
			||||||
    found = format_regex.match(data_string)
 | 
					    found = format_regex.match(data_string)
 | 
				
			||||||
    if not found:
 | 
					    if not found:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -223,6 +223,10 @@ class StrptimeTests(unittest.TestCase):
 | 
				
			||||||
        with self.assertRaises(ValueError) as e:
 | 
					        with self.assertRaises(ValueError) as e:
 | 
				
			||||||
            _strptime._strptime_time('', '%D')
 | 
					            _strptime._strptime_time('', '%D')
 | 
				
			||||||
        self.assertIs(e.exception.__suppress_context__, True)
 | 
					        self.assertIs(e.exception.__suppress_context__, True)
 | 
				
			||||||
 | 
					        # additional check for IndexError branch (issue #19545)
 | 
				
			||||||
 | 
					        with self.assertRaises(ValueError) as e:
 | 
				
			||||||
 | 
					            _strptime._strptime_time('19', '%Y %')
 | 
				
			||||||
 | 
					        self.assertIs(e.exception.__suppress_context__, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_unconverteddata(self):
 | 
					    def test_unconverteddata(self):
 | 
				
			||||||
        # Check ValueError is raised when there is unconverted data
 | 
					        # Check ValueError is raised when there is unconverted data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -198,6 +198,10 @@ class TimeTestCase(unittest.TestCase):
 | 
				
			||||||
        with self.assertRaises(ValueError) as e:
 | 
					        with self.assertRaises(ValueError) as e:
 | 
				
			||||||
            time.strptime('', '%D')
 | 
					            time.strptime('', '%D')
 | 
				
			||||||
        self.assertIs(e.exception.__suppress_context__, True)
 | 
					        self.assertIs(e.exception.__suppress_context__, True)
 | 
				
			||||||
 | 
					        # additional check for IndexError branch (issue #19545)
 | 
				
			||||||
 | 
					        with self.assertRaises(ValueError) as e:
 | 
				
			||||||
 | 
					            time.strptime('19', '%Y %')
 | 
				
			||||||
 | 
					        self.assertIs(e.exception.__suppress_context__, True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_asctime(self):
 | 
					    def test_asctime(self):
 | 
				
			||||||
        time.asctime(time.gmtime(self.t))
 | 
					        time.asctime(time.gmtime(self.t))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,9 @@ Core and Builtins
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Issue #19545: Avoid chained exceptions while passing stray % to
 | 
				
			||||||
 | 
					  time.strptime().  Initial patch by Claudiu Popa.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Issue #19633: Fixed writing not compressed 16- and 32-bit wave files on
 | 
					- Issue #19633: Fixed writing not compressed 16- and 32-bit wave files on
 | 
				
			||||||
  big-endian platforms.
 | 
					  big-endian platforms.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue