mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Complain if there is junk before the first category title
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
		
							parent
							
								
									e248e83f9f
								
							
						
					
					
						commit
						4d977a4f40
					
				@ -51,6 +51,12 @@ class InputFormatError(Exception):
 | 
			
		||||
                                     message.format(*args, **kwargs))
 | 
			
		||||
        super().__init__(message)
 | 
			
		||||
 | 
			
		||||
class CategoryParseError(Exception):
 | 
			
		||||
    def __init__(self, line_offset, error_message):
 | 
			
		||||
        self.line_offset = line_offset
 | 
			
		||||
        self.error_message = error_message
 | 
			
		||||
        super().__init__('{}: {}'.format(line_offset, error_message))
 | 
			
		||||
 | 
			
		||||
class LostContent(Exception):
 | 
			
		||||
    def __init__(self, filename, line):
 | 
			
		||||
        message = ('Lost content from {}: "{}"'.format(filename, line))
 | 
			
		||||
@ -143,9 +149,12 @@ class TextChangelogFormat(ChangelogFormat):
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def split_categories(cls, version_body):
 | 
			
		||||
        """A category title is a line with the title in column 0."""
 | 
			
		||||
        title_matches = list(re.finditer(cls._category_title_re, version_body))
 | 
			
		||||
        if not title_matches:
 | 
			
		||||
        if not version_body:
 | 
			
		||||
            return []
 | 
			
		||||
        title_matches = list(re.finditer(cls._category_title_re, version_body))
 | 
			
		||||
        if not title_matches or title_matches[0].start() != 0:
 | 
			
		||||
            # There is junk before the first category.
 | 
			
		||||
            raise CategoryParseError(0, 'Junk found where category expected')
 | 
			
		||||
        title_starts = [m.start(1) for m in title_matches]
 | 
			
		||||
        body_starts = [m.end(0) for m in title_matches]
 | 
			
		||||
        body_ends = title_starts[1:] + [len(version_body)]
 | 
			
		||||
@ -191,7 +200,11 @@ class ChangeLog:
 | 
			
		||||
    def add_categories_from_text(self, filename, line_offset,
 | 
			
		||||
                                 text, allow_unknown_category):
 | 
			
		||||
        """Parse a version section or entry file."""
 | 
			
		||||
        try:
 | 
			
		||||
            categories = self.format.split_categories(text)
 | 
			
		||||
        except CategoryParseError as e:
 | 
			
		||||
            raise InputFormatError(filename, line_offset + e.line_offset,
 | 
			
		||||
                                   e.error_message)
 | 
			
		||||
        for category in categories:
 | 
			
		||||
            if not allow_unknown_category and \
 | 
			
		||||
               category.name not in self.categories:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user