Mercurial > babel > mirror
changeset 448:9f1fb53b996f stable-0.9.x
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 | 6b29e23548ea |
children | 6639989432a9 |
files | ChangeLog babel/messages/pofile.py babel/messages/tests/pofile.py |
diffstat | 3 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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])
--- 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):