Skip to content

Commit

Permalink
[csv-] use newline='' for opening files
Browse files Browse the repository at this point in the history
The csv library documentation says
"If newline='' is not specified, newlines embedded inside quoted fields
will not be interpreted correctly [...] . It should always be safe
to specify newline='', since the csv module does its own (universal)
newline handling."
https://docs.python.org/3/library/csv.html#id4
  • Loading branch information
midichef committed Apr 7, 2024
1 parent 581cdf1 commit 50d2470
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Binary file modified tests/golden/errors-311.tsv
Binary file not shown.
2 changes: 1 addition & 1 deletion visidata/loaders/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def iterload(self):
import csv
csv.field_size_limit(2**31-1) #288 Windows has max 32-bit

with self.open_text_source() as fp:
with self.open_text_source(newline='') as fp:
if options.safety_first:
rdr = csv.reader(removeNulls(fp), **options.getall('csv_'))
else:
Expand Down
4 changes: 2 additions & 2 deletions visidata/text_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def __exit__(self, *args, **kwargs):


@BaseSheet.api
def open_text_source(sheet):
def open_text_source(sheet, newline=None):
'Open sheet source as text, using sheet options for encoding and regex_skip.'
fp = sheet.source.open(encoding=sheet.options.encoding, encoding_errors=sheet.options.encoding_errors)
fp = sheet.source.open(encoding=sheet.options.encoding, encoding_errors=sheet.options.encoding_errors, newline=newline)
regex_skip = sheet.options.regex_skip
if regex_skip:
return FilterFile(fp, regex_skip, sheet.regex_flags())
Expand Down

0 comments on commit 50d2470

Please sign in to comment.