Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116090
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/fast_sanitize/sanitizer.ex b/lib/fast_sanitize/sanitizer.ex
index 0dff4f9..e8cf598 100644
--- a/lib/fast_sanitize/sanitizer.ex
+++ b/lib/fast_sanitize/sanitizer.ex
@@ -1,63 +1,63 @@
defmodule FastSanitize.Sanitizer do
require Logger
alias FastSanitize.Fragment
@moduledoc """
Defines the contract that Sanitizer modules must follow.
"""
@doc """
Scrubs a document node.
"""
@callback scrub({atom(), list(), list()}) :: tuple()
@doc """
Scrubs an unknown node.
"""
@callback scrub({binary(), list(), list()}) :: tuple()
@doc """
Scrubs a text node.
"""
@callback scrub(binary()) :: binary()
# fallbacks
def scrub("", _), do: {:ok, ""}
def scrub(nil, _), do: {:ok, ""}
def scrub(doc, scrubber) when is_binary(doc) do
with wrapped_doc <- "<body>" <> doc <> "</body>",
{:ok, subtree} <- Fragment.to_tree(wrapped_doc) do
scrub(subtree, scrubber)
|> Fragment.to_html()
else
e ->
{:error, e}
end
end
def scrub(subtree, scrubber) when is_list(subtree) do
Logger.debug("Pre-process: #{inspect(subtree)}")
Enum.map(subtree, fn fragment ->
case scrubber.scrub(fragment) do
- {tag, attrs, nil} ->
- Logger.debug("Post-process closure: #{inspect({tag, attrs, nil})}")
- {tag, attrs, nil}
+ {_tag, _attrs, nil} = fragment ->
+ Logger.debug("Post-process closure: #{inspect(fragment)}")
+ fragment
{tag, attrs, children} ->
Logger.debug("Post-process tag: #{inspect({tag, attrs, children})}")
{tag, attrs, scrub(children, scrubber)}
subtree when is_list(subtree) ->
Logger.debug("Post-process subtree: #{inspect(subtree)}")
scrub(subtree, scrubber)
other ->
Logger.debug("Post-process other: #{inspect(other)}")
other
end
end)
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 30, 7:45 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41397
Default Alt Text
(1 KB)
Attached To
Mode
R15 fast_sanitize
Attached
Detach File
Event Timeline
Log In to Comment