Commit c1a2ba07 authored by Jérome Perrin's avatar Jérome Perrin

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
parent 75fcee23
...@@ -387,7 +387,7 @@ class LinesValidator(StringBaseValidator): ...@@ -387,7 +387,7 @@ class LinesValidator(StringBaseValidator):
if max_length and len(value) > max_length: if max_length and len(value) > max_length:
self.raise_error('too_long', field) self.raise_error('too_long', field)
# split input into separate lines # split input into separate lines
lines = value.split("\n") lines = value.splitlines()
# check whether we have too many lines # check whether we have too many lines
max_lines = field.get_value('max_lines') or 0 max_lines = field.get_value('max_lines') or 0
......
...@@ -444,6 +444,23 @@ class DateTimeValidatorTestCase(ValidatorTestCase): ...@@ -444,6 +444,23 @@ class DateTimeValidatorTestCase(ValidatorTestCase):
self.assertEquals(10, result.hour()) self.assertEquals(10, result.hour())
self.assertEquals(30, result.minute()) 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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -453,6 +470,7 @@ def test_suite(): ...@@ -453,6 +470,7 @@ def test_suite():
suite.addTest(unittest.makeSuite(IntegerValidatorTestCase, 'test')) suite.addTest(unittest.makeSuite(IntegerValidatorTestCase, 'test'))
suite.addTest(unittest.makeSuite(FloatValidatorTestCase, 'test')) suite.addTest(unittest.makeSuite(FloatValidatorTestCase, 'test'))
suite.addTest(unittest.makeSuite(DateTimeValidatorTestCase, 'test')) suite.addTest(unittest.makeSuite(DateTimeValidatorTestCase, 'test'))
suite.addTest(unittest.makeSuite(LinesValidatorTestCase, 'test'))
return suite return suite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment