misc: keep newlines in CSV import (#42624)

This commit is contained in:
Benjamin Dauvergne 2020-08-20 17:08:49 +02:00
parent 763451cb47
commit 7e392aeaa4
2 changed files with 3 additions and 2 deletions

View File

@ -6354,7 +6354,7 @@ def test_backoffice_cards_import_data_from_csv(pub, studio):
data = [b'Table,Map,Test,Boolean,List,Date,File,Email,Long,List2']
for i in range(1, 150):
data.append(b'table,48.81;2.37,data%d ,%s,item%d,2020-01-%02d,filename-%d,test@localhost,plop,1' % (
data.append(b'table,48.81;2.37,data%d ,%s,item%d,2020-01-%02d,filename-%d,test@localhost,"plop\nplop",1' % (
i, str(bool(i % 2)).encode('utf-8'), i, i % 31 + 1, i))
resp.forms[0]['file'] = Upload('test.csv', b'\n'.join(data),
@ -6368,6 +6368,7 @@ def test_backoffice_cards_import_data_from_csv(pub, studio):
assert card1.data['2'] == 'data1'
assert card1.data['3'] is True
assert card1.data['5'].tm_mday == 2
assert card1.data['9'] == 'plop\nplop'
assert card1.data['10'] == '1'
assert card1.data['10_display'] == 'un'
assert card1.data['10_structured'] == {'id': '1', 'text': 'un', 'more': 'foo'}

View File

@ -224,7 +224,7 @@ class CardPage(FormPage):
except csv.Error:
dialect = None
reader = csv.reader(content.splitlines(), dialect=dialect)
reader = csv.reader(content.splitlines(keepends=True), dialect=dialect)
try:
caption = next(reader)
except StopIteration: