Skip to content

Commit

Permalink
Correctly parse escaped fields at end of line when followed by a deli…
Browse files Browse the repository at this point in the history
…miter [fixes #89]
  • Loading branch information
beatrichartz committed Mar 30, 2019
1 parent a4b8395 commit de4db66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ mix.lock
.envrc
*.hist
*.ez
.tool-versions
3 changes: 3 additions & 0 deletions lib/csv/decoding/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ defmodule CSV.Decoding.Parser do
{:separator, _} ->
parse(row ++ [field |> strip(options)], "", tokens, :unescaped, options)

{:delimiter, _} ->
parse(row, field, tokens, :unescaped, options)

_ ->
{:error, StrayQuoteError, field}
end
Expand Down
7 changes: 7 additions & 0 deletions test/escaped_fields_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ defmodule EscapedFieldsTest do
assert result == [["a", "be\r\nc,d\r\ne,f"], ~w(g h)]
end

test "does parse escape sequences in each field correctly" do
stream = ["a,\"b\",\"c\"\n", "\"d\",e,\"f\"\"\"\n"] |> to_stream
result = CSV.decode(stream) |> Enum.take(2)

assert result == [ok: ["a", "b", "c"], ok: ["d", "e", "f\""]]
end

test "collects rows with fields and escape sequences spanning multiple lines" do
stream =
[
Expand Down

0 comments on commit de4db66

Please sign in to comment.