Skip to content

Commit

Permalink
fix: do not cast string/atom enum values
Browse files Browse the repository at this point in the history
- enum choices values should be treated as it are
  - strings aren't valid atoms choices:
    `"green" in [:green, :blue, :red]` should be false
  • Loading branch information
zoedsoupe committed Dec 3, 2024
1 parent 7e4358d commit fe453d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/peri.ex
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ defmodule Peri do
end

defp validate_field(val, {:enum, choices}, _data) do
if to_string(val) in Enum.map(choices, &to_string/1) do
if val in choices do
:ok
else
info = [choices: inspect(choices, pretty: true), actual: inspect(val)]
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Peri.MixProject do
use Mix.Project

@version "0.2.12"
@version "0.3.0"
@source_url "https://github.com/zoedsoupe/peri"

def project do
Expand Down

0 comments on commit fe453d1

Please sign in to comment.