From 1d11647b2f6c9eae2edaf98f38b62c0131825c6b Mon Sep 17 00:00:00 2001 From: Zoey de Souza Pessanha Date: Tue, 3 Dec 2024 18:21:02 -0300 Subject: [PATCH] fix: do not cast string/atom enum values - enum choices values should be treated as it are - strings aren't valid atoms choices: `"green" in [:green, :blue, :red]` should be false --- README.md | 2 +- lib/peri.ex | 2 +- mix.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 125d09b..28397fe 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add this line to your `mix.exs`: ```elixir defp deps do [ - {:peri, "~> 0.2"} + {:peri, "~> 0.3"} ] end ``` diff --git a/lib/peri.ex b/lib/peri.ex index 695f8f1..1542721 100644 --- a/lib/peri.ex +++ b/lib/peri.ex @@ -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)] diff --git a/mix.exs b/mix.exs index 4d51d66..2b24ed0 100644 --- a/mix.exs +++ b/mix.exs @@ -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