cldf / csvw

CSV on the web
Apache License 2.0
37 stars 6 forks source link

csvw.dsv roundtrip failiure with escapechar and QUOTE_NONE #4

Closed xflr6 closed 6 years ago

xflr6 commented 6 years ago
>>> import csv
>>> from csvw.dsv import UnicodeWriter, UnicodeReader
>>> kwargs = {'quoting': csv.QUOTE_NONE, 'escapechar': '\\'}
>>> row = ['\\spam']
>>> with UnicodeWriter(**kwargs) as writer:
    writer.writerow(row)
>>> writer.f.seek(0)
0
>>> with UnicodeReader(writer.f, **kwargs) as reader:
    result = next(reader)
>>> assert result == row
Traceback (most recent call last):
...
AssertionError
>>> result
['\\\\spam']

https://bugs.python.org/issue12178 only occurs with quoting dialects, so our workaround for it _escapedoubled() needs to be restricted to those dialects: https://github.com/cldf/csvw/blob/ecc8e74b53c7478b83d32d1c0fc19e2df4c7288f/csvw/dsv.py#L99-L109

xflr6 commented 6 years ago

See also https://github.com/cldf/csvw/blob/master/tests/test_csv_escapechar.py