changeset 358:c82ad0f5ff65

Fixed #59 by falling back silently on invalid location comments.
author aronacher
date Tue, 17 Jun 2008 20:40:36 +0000
parents 9acf6b5baa22
children 44637ad19c35
files babel/messages/pofile.py babel/messages/tests/pofile.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -208,8 +208,13 @@
                 _add_message()
             if line[1:].startswith(':'):
                 for location in line[2:].lstrip().split():
-                    filename, lineno = location.split(':', 1)
-                    locations.append((filename, int(lineno)))
+                    pos = location.rfind(':')
+                    if pos >= 0:
+                        try:
+                            lineno = int(location[pos + 1:])
+                        except ValueError:
+                            continue
+                        locations.append((location[:pos], lineno))
             elif line[1:].startswith(','):
                 for flag in line[2:].lstrip().split(','):
                     flags.append(flag.strip())
--- a/babel/messages/tests/pofile.py
+++ b/babel/messages/tests/pofile.py
@@ -380,6 +380,19 @@
 msgstr[1] "Voeh"''' in value
         assert value.find('msgid ""') < value.find('msgid "bar"') < value.find('msgid "foo"')
 
+    def test_silent_location_fallback(self):
+        buf = StringIO('''\
+#: broken_file.py
+msgid "missing line number"
+msgstr ""
+
+#: broken_file.py:broken_line_number
+msgid "broken line number"
+msgstr ""''')
+        catalog = pofile.read_po(buf)
+        self.assertEqual(catalog.get('missing line number').locations, [])
+        self.assertEqual(catalog.get('broken line number').locations, [])
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(pofile))
Copyright (C) 2012-2017 Edgewall Software