forked from CGM_Public/pretix_original
Order import: handle mixed endings of last line (Z#23230806) (#6066)
* handle mixed line endings in import * formatting
This commit is contained in:
committed by
GitHub
parent
c037fd865b
commit
5c7104634e
@@ -70,6 +70,10 @@ def parse_csv(file, length=None, mode="strict", charset=None):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
charset = file.charset
|
charset = file.charset
|
||||||
data = data.decode(charset or "utf-8", mode)
|
data = data.decode(charset or "utf-8", mode)
|
||||||
|
|
||||||
|
# remove stray linebreaks from the end of the file
|
||||||
|
data = data.rstrip("\n")
|
||||||
|
|
||||||
# If the file was modified on a Mac, it only contains \r as line breaks
|
# If the file was modified on a Mac, it only contains \r as line breaks
|
||||||
if '\r' in data and '\n' not in data:
|
if '\r' in data and '\n' not in data:
|
||||||
data = data.replace('\r', '\n')
|
data = data.replace('\r', '\n')
|
||||||
|
|||||||
@@ -991,3 +991,30 @@ def test_import_mixed_order_size_consistency(user, event, item):
|
|||||||
).get()
|
).get()
|
||||||
assert ('Inconsistent data in row 2: Column Email address contains value "a2@example.com", but for this order, '
|
assert ('Inconsistent data in row 2: Column Email address contains value "a2@example.com", but for this order, '
|
||||||
'the value has already been set to "a1@example.com".') in str(excinfo.value)
|
'the value has already been set to "a1@example.com".') in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@scopes_disabled()
|
||||||
|
def test_import_line_endings_mix(event, item, user):
|
||||||
|
# Ensures import works with mixed file endings.
|
||||||
|
# See Ticket#23230806 where a file to import ends with \r\n
|
||||||
|
settings = dict(DEFAULT_SETTINGS)
|
||||||
|
settings['item'] = 'static:{}'.format(item.pk)
|
||||||
|
|
||||||
|
cf = inputfile_factory()
|
||||||
|
file = cf.file
|
||||||
|
file.seek(0)
|
||||||
|
data = file.read()
|
||||||
|
data = data.replace(b'\n', b'\r')
|
||||||
|
data = data.rstrip(b'\r\r')
|
||||||
|
data = data + b'\r\n'
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
cf.file.save("input.csv", ContentFile(data))
|
||||||
|
cf.save()
|
||||||
|
|
||||||
|
import_orders.apply(
|
||||||
|
args=(event.pk, cf.id, settings, 'en', user.pk)
|
||||||
|
)
|
||||||
|
assert event.orders.count() == 3
|
||||||
|
assert OrderPosition.objects.count() == 3
|
||||||
|
|||||||
Reference in New Issue
Block a user