From: Bryn Truscott Date: Thu, 19 Jul 2018 14:50:16 +0000 (+0100) Subject: Small fixes to avoid stack traces due to badly formatted .po file X-Git-Tag: v2.7.0~27^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=359ecffca479dfe032d0f7210d5cd8160599c816;p=thirdparty%2Fbabel.git Small fixes to avoid stack traces due to badly formatted .po file --- diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index ea8d7d7e..fe376318 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -183,9 +183,12 @@ class PoFileParser(object): def _process_keyword_line(self, lineno, line, obsolete=False): for keyword in self._keywords: - if line.startswith(keyword) and line[len(keyword)] in [' ', '[']: - arg = line[len(keyword):] - break + try: + if line.startswith(keyword) and line[len(keyword)] in [' ', '[']: + arg = line[len(keyword):] + break + except IndexError: + self._invalid_pofile(line, lineno, "Keyword must be followed by a string") else: self._invalid_pofile(line, lineno, "Start of line didn't match any expected keyword.") return @@ -290,7 +293,7 @@ class PoFileParser(object): if self.abort_invalid: raise PoFileError(msg, self.catalog, line, lineno) print("WARNING:", msg) - print("WARNING: Problem on line {0}: {1}".format(lineno + 1, line)) + print(u"WARNING: Problem on line {0}: {1}".format(lineno + 1, line)) def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False, charset=None, abort_invalid=False):