diff --git a/lib/floki.ex b/lib/floki.ex index 8353b7c0..de1af63c 100644 --- a/lib/floki.ex +++ b/lib/floki.ex @@ -570,8 +570,7 @@ defmodule Floki do def text(html, opts \\ []) do defaults = [deep: true, js: false, style: true, sep: "", include_inputs: false] - # We can use `Keyword.validate!` when require Elixir 1.13 - opts = Keyword.merge(defaults, opts) + opts = Keyword.validate!(opts, defaults) cleaned_html_tree = html @@ -617,6 +616,8 @@ defmodule Floki do end def children({_, _, _} = html_node, opts) do + opts = Keyword.validate!(opts, include_text: true) + children(html_node, include_text: opts[:include_text]) end diff --git a/lib/floki/raw_html.ex b/lib/floki/raw_html.ex index 42c4fe84..41e72b9c 100644 --- a/lib/floki/raw_html.ex +++ b/lib/floki/raw_html.ex @@ -34,17 +34,19 @@ defmodule Floki.RawHTML do @encoder &Floki.Entities.encode/1 @no_encoder &Function.identity/1 - def raw_html(html_tree, options) do + def raw_html(html_tree, opts) do + opts = Keyword.validate!(opts, encode: true, pretty: false) + encoder = - case Keyword.fetch(options, :encode) do - {:ok, true} -> @encoder - {:ok, false} -> @no_encoder + case opts[:encode] do + true -> @encoder + false -> @no_encoder :error -> default_encoder() end padding = - case Keyword.fetch(options, :pretty) do - {:ok, true} -> %{pad: "", pad_increase: " ", line_ending: "\n", depth: 0} + case opts[:pretty] do + true -> %{pad: "", pad_increase: " ", line_ending: "\n", depth: 0} _ -> :noop end diff --git a/test/floki_test.exs b/test/floki_test.exs index 0bfb66a5..876716c0 100644 --- a/test/floki_test.exs +++ b/test/floki_test.exs @@ -1606,8 +1606,14 @@ defmodule FlokiTest do assert Floki.children(html_node) == expected assert Floki.children(html_node, include_text: true) == expected - assert Floki.children(html_node, include_text: true, unknown_option: true) == expected - assert Floki.children(html_node, unknown_option: true) == expected + + assert_raise ArgumentError, fn -> + Floki.children(html_node, include_text: true, unknown_option: true) + end + + assert_raise ArgumentError, fn -> + Floki.children(html_node, unknown_option: true) + end end test "returns the children elements of an element without the text" do @@ -1622,7 +1628,10 @@ defmodule FlokiTest do ] assert Floki.children(elements, include_text: false) == expected - assert Floki.children(elements, include_text: false, unknown_option: true) == expected + + assert_raise ArgumentError, fn -> + Floki.children(elements, include_text: false, unknown_option: true) + end end test "returns nil if the given html is not a valid tuple" do