0001-csvdatasource-validate-CSV-file-in-clean-39971.patch
passerelle/apps/csvdatasource/models.py | ||
---|---|---|
149 | 149 |
self._detect_dialect_options() |
150 | 150 |
except Exception as e: |
151 | 151 |
raise ValidationError(_('Could not detect CSV dialect: %s') % e) |
152 |
try: |
|
153 |
self.get_rows() |
|
154 |
except Exception as e: |
|
155 |
raise ValidationError(_('Invalid CSV file: %s') % e) |
|
152 | 156 |
return super(CsvDataSource, self).clean(*args, **kwargs) |
153 | 157 | |
154 | 158 |
def _detect_dialect_options(self): |
tests/test_csv_datasource.py | ||
---|---|---|
751 | 751 |
assert 'Could not detect CSV dialect' in resp |
752 | 752 | |
753 | 753 | |
754 |
def test_csv_validation(admin_user, app): |
|
755 |
app = login(app) |
|
756 |
resp = app.get('/manage/csvdatasource/add') |
|
757 |
form = resp.form |
|
758 |
form.set('title', 'Title') |
|
759 |
form.set('description', 'Description') |
|
760 |
form.set('csv_file', webtest.Upload('test.csv', b'a,b,c\n1,2\0,3\n4,5,6', 'application/octet-stream')) |
|
761 |
resp = form.submit() |
|
762 |
assert 'Invalid CSV file: line contains NUL' in resp |
|
763 | ||
764 | ||
754 | 765 |
def test_change_csv_command(setup): |
755 | 766 |
csv, url = setup(data=StringIO(data)) |
756 | 767 |
call_command('change-csv', 'test', os.path.join(TEST_BASE_DIR, 'data-empty.ods')) |
757 |
- |