Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F116032
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/fast_sanitize/sanitizer.ex b/lib/fast_sanitize/sanitizer.ex
index e8cf598..d69946b 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} = fragment ->
Logger.debug("Post-process closure: #{inspect(fragment)}")
- 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
diff --git a/mix.exs b/mix.exs
index 6dea713..eb9b317 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,31 +1,34 @@
defmodule FastSanitize.MixProject do
use Mix.Project
def project do
[
app: :fast_sanitize,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:plug, "~> 1.8"},
- {:myhtmlex, git: "https://github.com/rinpatch/myhtmlex.git", ref: "d973dfb1b252b1c6e6eddddc18c0895aa977091c", submodules: true},
+ {:myhtmlex,
+ git: "https://github.com/rinpatch/myhtmlex.git",
+ ref: "d973dfb1b252b1c6e6eddddc18c0895aa977091c",
+ submodules: true},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0-rc.5", only: [:dev], runtime: false}
]
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 30, 2:59 AM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41352
Default Alt Text
(2 KB)
Attached To
Mode
R15 fast_sanitize
Attached
Detach File
Event Timeline
Log In to Comment