Project

General

Profile

0001-csv_import-ignore-BOM-43627.patch

Valentin Deniaud, 18 Jun 2020 05:48 PM

Download (1.7 KB)

View differences:

Subject: [PATCH] csv_import: ignore BOM (#43627)

 src/authentic2/manager/forms.py | 2 +-
 tests/test_csv_import.py        | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
src/authentic2/manager/forms.py
664 664

  
665 665

  
666 666
ENCODINGS = [
667
    ('utf-8', _('Unicode (UTF-8)')),
667
    ('utf-8-sig', _('Unicode (UTF-8)')),
668 668
    ('cp1252', _('Western Europe (Windows-1252)')),
669 669
    ('iso-8859-15', _('Western Europe (ISO-8859-15)')),
670 670
]
tests/test_csv_import.py
20 20
import pytest
21 21

  
22 22
import io
23
import codecs
23 24

  
24 25
from django.core import mail
25 26

  
......
134 135
    assert importer.errors == [Error('too-many-key-columns')]
135 136

  
136 137

  
138
def test_bom_character(profile, user_csv_importer_factory):
139
    content = codecs.BOM_UTF8 + 'email key,first_name\ntest@entrouvert.org,hop'.encode('utf-8')
140
    file_content = io.BytesIO(content)
141
    importer = UserCsvImporter()
142
    assert importer.run(file_content, 'utf-8-sig')
143
    assert not importer.has_errors
144

  
145

  
137 146
def test_run(profile, user_csv_importer_factory):
138 147
    assert User.objects.count() == 0
139 148
    content = '''email key,first_name,last_name,phone update
140
-