summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2018-07-20 16:54:39 +0300
committerGitHub <noreply@github.com>2018-07-20 16:54:39 +0300
commita865f8ef86f687c06b36ec178c2021ce0c368c63 (patch)
tree264899fb046c7baa0f7e1e5eeccd23fd69836d88
parent83f959ebf23266b5ae7432589c2f4983f0d817b4 (diff)
parent3f1dffbb2dffc88957384fc4af378003299c68db (diff)
downloadbabel-a865f8ef86f687c06b36ec178c2021ce0c368c63.tar.gz
Merge pull request #597 from BBOXX/error-msg-fix
Small fixes to avoid stack traces due to badly formatted .po file
-rw-r--r--babel/messages/pofile.py11
-rw-r--r--tests/messages/test_pofile.py12
2 files changed, 9 insertions, 14 deletions
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py
index ea8d7d7..fe37631 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):
diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py
index 5313329..9872e9d 100644
--- a/tests/messages/test_pofile.py
+++ b/tests/messages/test_pofile.py
@@ -456,16 +456,8 @@ msgstr[2] "Vohs [text]"
'''
# Catalog not created, throws Unicode Error
buf = StringIO(invalid_po)
- output = None
-
- # This should only be thrown under py27
- if sys.version_info.major == 2:
- with self.assertRaises(UnicodeEncodeError):
- output = pofile.read_po(buf, locale='fr', abort_invalid=False)
- assert not output
- else:
- output = pofile.read_po(buf, locale='fr', abort_invalid=False)
- assert isinstance(output, Catalog)
+ output = pofile.read_po(buf, locale='fr', abort_invalid=False)
+ assert isinstance(output, Catalog)
# Catalog not created, throws PoFileError
buf = StringIO(invalid_po_2)