mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-04 04:31:14 -06:00
Raise ValidationError on invalid CSV values.
https://fedorahosted.org/freeipa/ticket/3323
This commit is contained in:
parent
cbb262dc07
commit
1d35043e46
@ -694,9 +694,16 @@ class Param(ReadOnly):
|
||||
delimiter=self.csv_separator, quotechar='"',
|
||||
skipinitialspace=self.csv_skipspace,
|
||||
**kwargs)
|
||||
for row in csv_reader:
|
||||
# decode UTF-8 back to Unicode, cell by cell:
|
||||
yield [unicode(cell, 'utf-8') for cell in row]
|
||||
try:
|
||||
for row in csv_reader:
|
||||
# decode UTF-8 back to Unicode, cell by cell:
|
||||
yield [unicode(cell, 'utf-8') for cell in row]
|
||||
except csv.Error, e:
|
||||
raise ValidationError(
|
||||
name=self.get_param_name(),
|
||||
value=unicode_csv_data,
|
||||
error=_("Improperly formatted CSV value (%s)" % e)
|
||||
)
|
||||
|
||||
def split_csv(self, value):
|
||||
"""Split CSV strings into individual values.
|
||||
|
@ -631,6 +631,10 @@ class test_Param(ClassChecker):
|
||||
assert type(n) is tuple
|
||||
assert len(n) is 3
|
||||
|
||||
e = raises(ValidationError, o.split_csv, '"a')
|
||||
assert e.name == 'my_list'
|
||||
assert e.error == u'Improperly formatted CSV value (newline inside string)'
|
||||
|
||||
def test_split_csv_separator(self):
|
||||
"""
|
||||
Test the `ipalib.parameters.Param.split_csv` method with csv and a separator.
|
||||
|
Loading…
Reference in New Issue
Block a user