Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/solid/matcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ end
defimpl Solid.Matcher, for: Any do
def match(data, []), do: {:ok, data}

def match(_, _), do: {:error, :not_found}
def match(data, _) do
raise Protocol.UndefinedError,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to raise, you must at least check that strict mode is on.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we might want to return a different error tuple here and use Context.put_errors to add a new error IF strict_variables=true. If not true we just ignore

protocol: @protocol,
value: data
end
end

defimpl Solid.Matcher, for: Integer do
def match(data, []), do: {:ok, data}

def match(_data, _), do: {:error, :not_found}
end

defimpl Solid.Matcher, for: List do
Expand Down
20 changes: 20 additions & 0 deletions test/solid_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ defmodule SolidTest do
|> Solid.render!(%{})
|> IO.iodata_to_binary() == "yofoo"
end

test "protcol not implemented for structs" do
template = "{{ var1 }}"

assert_raise(Protocol.UndefinedError, fn ->
template
|> Solid.parse!()
|> Solid.render!(%{__struct__: MyStruct, var1: "yo"})
end)
end

test "protcol not implemented for floats" do
template = "{{ var1 }}"

assert_raise(Protocol.UndefinedError, fn ->
template
|> Solid.parse!()
|> Solid.render!(3.14)
end)
end
end

describe "strict_variables" do
Expand Down