From c1a2ba0732fd31c4f54ded521ac1a9a71da63eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Mon, 3 May 2010 09:03:56 +0000 Subject: [PATCH] use splitlines instead of split('\n'), because the later does not work in conjunction with whitespace_preserve. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34924 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/Formulator/Validator.py | 2 +- product/Formulator/tests/testFormValidator.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/product/Formulator/Validator.py b/product/Formulator/Validator.py index ace0f749f2..39f427e70c 100644 --- a/product/Formulator/Validator.py +++ b/product/Formulator/Validator.py @@ -387,7 +387,7 @@ class LinesValidator(StringBaseValidator): if max_length and len(value) > max_length: self.raise_error('too_long', field) # split input into separate lines - lines = value.split("\n") + lines = value.splitlines() # check whether we have too many lines max_lines = field.get_value('max_lines') or 0 diff --git a/product/Formulator/tests/testFormValidator.py b/product/Formulator/tests/testFormValidator.py index 87c448b0db..0777892fc6 100644 --- a/product/Formulator/tests/testFormValidator.py +++ b/product/Formulator/tests/testFormValidator.py @@ -444,6 +444,23 @@ class DateTimeValidatorTestCase(ValidatorTestCase): self.assertEquals(10, result.hour()) self.assertEquals(30, result.minute()) +class LinesValidatorTestCase(ValidatorTestCase): + def setUp(self): + self.v = Validator.LinesValidatorInstance + + def test_basic(self): + result = self.v.validate( + TestField('f',), + 'f', {'f' : 'foo\r\nbar'}) + self.assertEqual(['foo', 'bar'], result) + + def test_preserve_whitespace(self): + result = self.v.validate( + TestField('f', whitespace_preserve=True), + 'f', {'f' : 'foo\r\nbar '}) + self.assertEqual(['foo', 'bar '], result) + + def test_suite(): suite = unittest.TestSuite() @@ -453,6 +470,7 @@ def test_suite(): suite.addTest(unittest.makeSuite(IntegerValidatorTestCase, 'test')) suite.addTest(unittest.makeSuite(FloatValidatorTestCase, 'test')) suite.addTest(unittest.makeSuite(DateTimeValidatorTestCase, 'test')) + suite.addTest(unittest.makeSuite(LinesValidatorTestCase, 'test')) return suite -- 2.30.9