# HG changeset patch # User jruigrok # Date 1267016375 0 # Node ID 9f1fb53b996f553559387fbaad37fe4d9e82cafa # Parent 6b29e23548ea57895efbc537e5247c7cabad310f Backport r483. This fixes messages containing square brackets from failing with unpack errors. Submitted by: Benoit Boissinot diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/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) diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/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]) diff --git a/babel/messages/tests/pofile.py b/babel/messages/tests/pofile.py --- a/babel/messages/tests/pofile.py +++ b/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):