Commit 91857de5 authored by kaniini's avatar kaniini

fragment: handle generic non-subtree tags

parent 275d4fd2
......@@ -31,13 +31,10 @@ defmodule FastSanitize.Fragment do
# comment node
defp fragment_to_html({:comment, _, text}), do: "<!-- #{text} -->"
# tags like <link> - useful attributes, no terminator
defp fragment_to_html({:link, attrs, _}), do: build_start_tag("link", attrs)
# tags like <hr> and <br> - no useful attributes, no terminator
defp fragment_to_html({:hr, _, _}), do: "<hr>"
defp fragment_to_html({:br, _, _}), do: "<br>"
# a node which can never accept children will have nil instead of a subtree
defp fragment_to_html({tag, attrs, nil}), do: build_start_tag(tag, attrs)
# every other case, assume a subtree
defp fragment_to_html({tag, attrs, subtree}) do
with start_tag <- build_start_tag(tag, attrs),
end_tag <- "</#{tag}>",
......
......@@ -15,7 +15,7 @@ defmodule FastSanitize.Fragment.Test do
end
test "it works for simple fragment trees with atypical tags" do
tree = [{:br, [], []}, {:hr, [], []}]
tree = [{:br, [], nil}, {:hr, [], nil}]
{:ok, "<br><hr>"} = FastSanitize.Fragment.to_html(tree)
end
......@@ -27,7 +27,7 @@ defmodule FastSanitize.Fragment.Test do
{"rel", "stylesheet"},
{"type", "text/css"},
{"href", "http://example.com/example.css"}
], []}
], nil}
]
{:ok, "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://example.com/example.css\">"} =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment