]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Small fixes to avoid stack traces due to badly formatted .po file
authorBryn Truscott <b.truscott@bboxx.co.uk>
Thu, 19 Jul 2018 14:50:16 +0000 (15:50 +0100)
committerBryn Truscott <b.truscott@bboxx.co.uk>
Thu, 19 Jul 2018 14:50:16 +0000 (15:50 +0100)
babel/messages/pofile.py

index ea8d7d7e24ab4e5b5547b12d8c7117787f359c03..fe376318adf625fa197a4c184cb7ca443f771821 100644 (file)
@@ -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):