From 4eec33c781c4f9d5c962943a0facb3cdfa34d1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Glauco=20Cust=C3=B3dio?= Date: Fri, 9 Oct 2015 16:04:33 -0300 Subject: [PATCH 1/2] Fix HTML comment in raw_html --- lib/floki.ex | 1 + test/floki_test.exs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/floki.ex b/lib/floki.ex index 5a6def7f..d4690da4 100644 --- a/lib/floki.ex +++ b/lib/floki.ex @@ -95,6 +95,7 @@ defmodule Floki do defp raw_html([], html), do: html defp raw_html(tuple, html) when is_tuple(tuple), do: raw_html([tuple], html) defp raw_html([value|tail], html) when is_binary(value), do: raw_html(tail, html <> value) + defp raw_html([{elem, value}|tail], html) when elem == :comment, do: raw_html(tail, html <> "") defp raw_html([{elem, attrs, value}|tail], html) do raw_html(tail, html <> tag_for(elem, attrs |> tag_attrs, value)) end diff --git a/test/floki_test.exs b/test/floki_test.exs index 29f5fd04..8885fae1 100644 --- a/test/floki_test.exs +++ b/test/floki_test.exs @@ -47,7 +47,7 @@ defmodule FlokiTest do """ - + @html_without_html_tag """

One

Two

@@ -144,6 +144,11 @@ defmodule FlokiTest do assert raw_html == String.split(raw_html, "\n") |> Enum.map(&(String.strip(&1))) |> Enum.join("") end + test "raw_html (with comment)" do + raw_html = Floki.parse(@html_with_img) |> Floki.raw_html + assert raw_html == String.split(raw_html, "\n") |> Enum.map(&(String.strip(&1))) |> Enum.join("") + end + test "raw_html (after find)" do raw_html = Floki.parse(@basic_html) |> Floki.find("a") |> Floki.raw_html assert raw_html == ~s(UOL) From 640ddc03bb626d0895a8e4da8d2ce5f96d233b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Glauco=20Cust=C3=B3dio?= Date: Fri, 9 Oct 2015 16:54:30 -0300 Subject: [PATCH 2/2] Replacing guard cause in favor of pattern match --- lib/floki.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/floki.ex b/lib/floki.ex index d4690da4..f203681f 100644 --- a/lib/floki.ex +++ b/lib/floki.ex @@ -95,7 +95,7 @@ defmodule Floki do defp raw_html([], html), do: html defp raw_html(tuple, html) when is_tuple(tuple), do: raw_html([tuple], html) defp raw_html([value|tail], html) when is_binary(value), do: raw_html(tail, html <> value) - defp raw_html([{elem, value}|tail], html) when elem == :comment, do: raw_html(tail, html <> "") + defp raw_html([{:comment, value}|tail], html), do: raw_html(tail, html <> "") defp raw_html([{elem, attrs, value}|tail], html) do raw_html(tail, html <> tag_for(elem, attrs |> tag_attrs, value)) end