changeset 450:fb4e025f3410 stable

Backport r483. This fixes messages containing square brackets from failing with unpack errors. Submitted by: Benoit Boissinot
author jruigrok
date Wed, 24 Feb 2010 12:59:35 +0000
parents 0fb7125f0b7a
children 8941027e8b22
files 0.9.x/ChangeLog 0.9.x/babel/messages/pofile.py 0.9.x/babel/messages/tests/pofile.py
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/0.9.x/ChangeLog
+++ b/0.9.x/ChangeLog
@@ -1,3 +1,11 @@
+Version 0.9.5
+http://svn.edgewall.org/repos/babel/tags/0.9.5/
+(? ? 2010, from branches/stable/0.9.x)
+
+ * Fixed the case where messages containing square brackets would break with
+   an unpack error.
+
+
 Version 0.9.4
 http://svn.edgewall.org/repos/babel/tags/0.9.4/
 (Aug 25 2008, from branches/stable/0.9.x)
--- a/0.9.x/babel/messages/pofile.py
+++ b/0.9.x/babel/messages/pofile.py
@@ -184,7 +184,7 @@
             in_msgstr[0] = True
             msg = line[6:].lstrip()
             if msg.startswith('['):
-                idx, msg = msg[1:].split(']')
+                idx, msg = msg[1:].split(']', 1)
                 translations.append([int(idx), msg.lstrip()])
             else:
                 translations.append([0, msg])
--- a/0.9.x/babel/messages/tests/pofile.py
+++ b/0.9.x/babel/messages/tests/pofile.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2007 Edgewall Software
+# Copyright (C) 2007-2010 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -167,6 +167,17 @@
         self.assertEqual(3, len(message.string))
         self.assertEqual('', message.string[2])
 
+    def test_plural_with_square_brackets(self):
+        buf = StringIO(r'''msgid "foo"
+msgid_plural "foos"
+msgstr[0] "Voh [text]"
+msgstr[1] "Vohs [text]"''')
+        catalog = pofile.read_po(buf, locale='nb_NO')
+        self.assertEqual(1, len(catalog))
+        self.assertEqual(2, catalog.num_plurals)
+        message = catalog['foo']
+        self.assertEqual(2, len(message.string))
+
 
 class WritePoTestCase(unittest.TestCase):
 
Copyright (C) 2012-2017 Edgewall Software