diff --git a/lib/bson/types.ex b/lib/bson/types.ex index 4062a20..7095469 100644 --- a/lib/bson/types.ex +++ b/lib/bson/types.ex @@ -124,7 +124,7 @@ defmodule BSON.ObjectId do defp e(unquote(int)), do: unquote(char) end - for {char, int} <- Enum.with_index(?A..?F) do + for {char, int} <- Enum.with_index(?A..?F, 10) do defp d(unquote(char)), do: unquote(int) end diff --git a/test/bson/types_test.exs b/test/bson/types_test.exs index 0d33bbd..f60bc73 100644 --- a/test/bson/types_test.exs +++ b/test/bson/types_test.exs @@ -11,6 +11,7 @@ defmodule BSON.TypesTest do @objectid %BSON.ObjectId{value: <<29, 32, 69, 244, 101, 119, 228, 28, 61, 24, 21, 215>>} @string "1d2045f46577e41c3d1815d7" + @string_uppercase "1D2045F46577E41C3D1815D7" @timestamp DateTime.from_unix!(488_654_324) test "inspect BSON.ObjectId" do @@ -39,6 +40,14 @@ defmodule BSON.TypesTest do end end + test "BSON.ObjectId.decode!/1 for uppercase HEX" do + assert BSON.ObjectId.decode!(@string_uppercase) == @objectid + + assert_raise FunctionClauseError, fn -> + BSON.ObjectId.decode!("") + end + end + test "BSON.ObjectId.encode/1" do assert BSON.ObjectId.encode(@objectid) == {:ok, @string} assert BSON.ObjectId.encode("") == :error