Commit 151d6d4a authored by rinpatch's avatar rinpatch

parse_fragment: fix {:error, :badmatch} when the option list is passed

All lists with items have an empty list as tail, so we need to decode
that before we get to the next argument
parent b1e086de
Pipeline #21006 passed with stage
in 40 seconds
......@@ -204,7 +204,6 @@ static void handle_send (state_t * state, erlang_msg * emsg)
goto out;
}
// the tuple should begin with a `decode` atom.
char atom[MAXATOMLEN];
if (ei_decode_atom (state->buffer.buff, &state->buffer.index, atom) < 0)
{
......@@ -252,6 +251,11 @@ static void handle_send (state_t * state, erlang_msg * emsg)
parse_flags_t parse_flags = decode_parse_flags (state, arity);
// Lists with items always have an empty list as their tail
if (arity != 0)
if (ei_decode_list_header (state->buffer.buff, &state->buffer.index, &arity) < 0)
panic ("failed to decode empty list header after option list in message");
// if we are parsing a fragment, context tag name should come next
myhtml_tag_id_t context_tag_id = 0;
if (fragment) {
......
......@@ -86,6 +86,8 @@ defmodule :fast_html do
{:ok, [{"html", [], ["rin is the <i>best</i> girl"]}]}
iex> :fast_html.decode_fragment("rin is the <i>best</i> girl", context: "objective_truth")
{:error, :unknown_context_tag}
iex> :fast_html.decode_fragment("rin is the <i>best</i> girl", format: [:html_atoms])
{:ok, [{:html, [], ["rin is the ", {:i, [], ["best"]}, " girl"]}]}
"""
def decode_fragment(bin, opts \\ []) do
flags = Keyword.get(opts, :format, [])
......
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