Skip to content

Commit

Permalink
Email addresses with different cases are considered equal
Browse files Browse the repository at this point in the history
  • Loading branch information
sax committed May 31, 2024
1 parent ded50bc commit ca2c6cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Change log

- Email addresses with different cases are considered equal.
- **Breaking change:** Use `EctoEmail` instead of `Ecto.Email`.

## 1.0.0
Expand Down
1 change: 1 addition & 0 deletions lib/ecto_email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ defmodule EctoEmail do
"""
@impl Ecto.Type
def equal?(address, address) when is_binary(address), do: true
def equal?(left, right) when is_binary(left) and is_binary(right), do: String.downcase(left) == String.downcase(right)
def equal?(_, _), do: false

@doc "Callback implementation for `c:Ecto.Type.load/1`"
Expand Down
4 changes: 4 additions & 0 deletions test/ecto_email_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ defmodule EctoEmailTest do
assert "[email protected]" |> EctoEmail.equal?("[email protected]")
end

test "is true when the addresses have the same content but different case" do
assert "[email protected]" |> EctoEmail.equal?("[email protected]")
end

test "is false when the addresses are the same" do
refute "[email protected]" |> EctoEmail.equal?("[email protected]")
end
Expand Down

0 comments on commit ca2c6cd

Please sign in to comment.