Projet

Général

Profil

0001-csv_import-handle-null-bytes-53323.patch

Valentin Deniaud, 29 avril 2021 14:09

Télécharger (1,87 ko)

Voir les différences:

Subject: [PATCH] csv_import: handle null bytes (#53323)

 src/authentic2/csv_import.py |  8 ++++++--
 tests/test_csv_import.py     | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
src/authentic2/csv_import.py
172 172
            if not dialect:
173 173
                self.error = Error('unknown-csv-dialect', _('Unknown CSV dialect'))
174 174
                return False
175
            reader = UnicodeReader(input_fd, dialect)
176
            self.rows = list(reader)
175
            try:
176
                reader = UnicodeReader(input_fd, dialect)
177
                self.rows = list(reader)
178
            except (csv.Error, TypeError) as e:
179
                self.error = Error('csv-read-error', _('Cannot read CSV: %s') % e)
180
                return False
177 181
            return True
178 182

  
179 183
        with input_fd:
tests/test_csv_import.py
93 93
    assert importer.error == Error('bad-encoding')
94 94

  
95 95

  
96
def test_null_byte(profile):
97
    importer = CsvImporter()
98
    assert not importer.run(b'email key,first_name\n1,\x00', 'ascii')
99
    assert importer.error == Error('csv-read-error')
100

  
101
    importer = CsvImporter()
102
    assert not importer.run(b'\x00', 'ascii')
103
    assert importer.error == Error('csv-read-error')
104

  
105

  
96 106
def test_empty_header_row_error(profile, user_csv_importer_factory):
97 107
    importer = user_csv_importer_factory('\n1,2,3')
98 108
    assert not importer.run()
99
-