Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrichartz committed Nov 26, 2023
2 parents d380dd4 + 41616d7 commit a83ca4a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 3.2.1 (2023-11-26)
- Correct typespec for decode, reported in [#125](https://github.com/beatrichartz/csv/issues/125) by [@AntoineAugusti](https://github.com/AntoineAugusti)

## 3.2.0 (2023-09-24)
- Strict mode: Exception messages of _thrown_ exceptions are now redacted by default to avoid data unintentionally leaking into logs.
This behaviour change is not considered to be breaking backwards compatibility since source data presented in exception messages is
Expand Down
7 changes: 4 additions & 3 deletions lib/csv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ defmodule CSV do
| {:validate_row_length, boolean()}
| {:escape_character, char()}
| {:escape_max_lines, integer()}
| ({:redact_errors, boolean()}
| {:unredact_exceptions, boolean()})

@spec decode(Enumerable.t(), [decode_options() | {:redact_errors, boolean()}]) :: Enumerable.t()
@spec decode(Enumerable.t(), [decode_options()]) :: Enumerable.t()
def decode(stream, options \\ []) do
stream |> Decoder.decode(options) |> inline_errors!(options)
end
Expand Down Expand Up @@ -288,8 +290,7 @@ defmodule CSV do
"""

@spec decode!(Enumerable.t(), [decode_options() | {:unredact_exceptions, boolean()}]) ::
Enumerable.t()
@spec decode!(Enumerable.t(), [decode_options()]) :: Enumerable.t()
def decode!(stream, options \\ []) do
stream |> Decoder.decode(options) |> raise_errors!(options)
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule CSV.Mixfile do
def project do
[
app: :csv,
version: "3.2.0",
version: "3.2.1",
elixir: "~> 1.5",
deps: deps(),
package: package(),
Expand Down
28 changes: 28 additions & 0 deletions test/dialyzer/decode_typespectest.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
defmodule DecodeTypespectest do
@moduledoc "Test decoding typespecs"

def test_decode_no_options do
["dummy,input"] |> CSV.decode() |> Enum.to_list()
end

def test_decode_option_escape_character do
["dummy,input"] |> CSV.decode(escape_character: ?.) |> Enum.to_list()
end
Expand Down Expand Up @@ -32,4 +36,28 @@ defmodule DecodeTypespectest do
def test_decode_option_headers_atom_list do
["dummy,input"] |> CSV.decode(headers: [:a, :b]) |> Enum.to_list()
end

def test_decode_combined do
["dummy,input"] |> CSV.decode(headers: [:a, :b], separator: ?,, validate_row_length: true) |> Enum.to_list()
end

def test_decode_option_combine_with_redact_errors do
["dummy,input"] |> CSV.decode(headers: [:a, :b], redact_errors: false) |> Enum.to_list()
end

def test_decode_strict_no_options do
["dummy,input"] |> CSV.decode!() |> Enum.to_list()
end

def test_decode_strict_headers do
["dummy,input"] |> CSV.decode!(headers: [:a, :b]) |> Enum.to_list()
end

def test_decode_strict_combined do
["dummy,input"] |> CSV.decode!(headers: [:a, :b], separator: ?,, validate_row_length: true) |> Enum.to_list()
end

def test_decode_strict_option_combine_with_unredact_exceptions do
["dummy,input"] |> CSV.decode!(headers: [:a, :b], unredact_exceptions: true) |> Enum.to_list()
end
end

0 comments on commit a83ca4a

Please sign in to comment.