Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final escaped field value lost when trailing newline is absent #117

Closed
superhawk610 opened this issue Nov 1, 2022 · 4 comments
Closed

Comments

@superhawk610
Copy link

When the final value on the final line of a file without a trailing newline is escaped (wrapped in quotes), it's dropped from the output and an empty string is returned instead. For example:

Budget
$2500.00

will output %{"Budget" => "$2500.00"}, but

Budget
"$2500.00"

will output %{"Budget" => ""}.

Note that this only occurs when the trailing newline is omitted from the file, regardless of line endings (LF or CRLF both exhibit this behaviour). If the trailing newline is present, this behaviour does not occur.

I would expect "$2500.00" to be returned for Budget in both cases above, regardless of whether it's wrapped in escape characters or not.

Steps to Reproduce

parse_csv = fn path ->
  path
  |> Path.expand()
  |> File.stream!([:utf8])
  |> CSV.decode!(headers: true)
  |> Enum.to_list()
end

parse_csv.("~/Downloads/with-quotes.csv")
#=> [%{"Budget" => ""}]

parse_csv.("~/Downloads/without-quotes.csv")
#=> [%{"Budget" => "$2500.00"}]

CSV Files

with-quotes.csv
without-quotes.csv

@superhawk610
Copy link
Author

This issue was introduced in 3.0.0 - I cannot reproduce it on 2.5.0.

@superhawk610
Copy link
Author

It seems this may be related to #112. If it's much effort to fix, just adding a note in the changelog/readme that a trailing newline is required would be helpful.

@beatrichartz
Copy link
Owner

Thanks for this - does this still happen in 3.0.1? Only checking since you mentioned 3.0.0 and some related issues have been fixed in 3.0.1

@beatrichartz
Copy link
Owner

I was able to reproduce this, will release the fix in 3.0.2. Thanks again! Feel free to reopen if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants