Skip to content

Commit 01cf1c3

Browse files
committed
Fix format validation bug
1 parent d8c729a commit 01cf1c3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/jsonrpc2_plug/validator.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defmodule JSONRPC2Plug.Validator do
5454
if is_nil(value) || (is_binary(value) && Regex.match?(regex, value)) do
5555
:ok
5656
else
57-
{:error, "does not match format %{format}", [format: regex]}
57+
{:error, "does not match format %{format}", [format: Regex.source(regex)]}
5858
end
5959
end
6060
end

test/jsonrpc2_plug/validator_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ defmodule JSONRPC2Plug.ValidatorTest do
2525
end
2626

2727
test ".format" do
28-
assert {:error, "does not match format %{format}", [format: ~r/some/]} = Validator.format(~r/some/).("xxx")
29-
assert {:error, "does not match format %{format}", [format: ~r/some/]} = Validator.format(~r/some/).(123)
28+
assert {:error, "does not match format %{format}", [format: "some"]} = Validator.format(~r/some/).("xxx")
29+
assert {:error, "does not match format %{format}", [format: "some"]} = Validator.format(~r/some/).(123)
3030
assert :ok = Validator.format(~r/some/).(nil)
3131
assert :ok = Validator.format(~r/some/).("something")
3232
end

0 commit comments

Comments
 (0)