Skip to content

Commit

Permalink
Fix wrong assignment in the mochiweb parser
Browse files Browse the repository at this point in the history
Erlang does not allow rebindings.

Closes #492
  • Loading branch information
philss committed Oct 16, 2023
1 parent bc410df commit 000f4be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/floki_mochi_html.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ tree([{doctype, _} | Rest], Stack, Opts) ->
tree(Rest, Stack, Opts).

norm({Tag, Attrs}, Opts) ->
Attrs = [{norm(K, Opts), iolist_to_binary(V)} || {K, V} <- Attrs],
Attrs0 = [{norm(K, Opts), iolist_to_binary(V)} || {K, V} <- Attrs],
case lists:keyfind(attributes_as_maps, 1, Opts) of
{attributes_as_maps, true} ->
% The HTML specs says we should ignore duplicated attributes and keep the first
% occurence of a given key.
% Since `maps:from_list/1` does the opposite, we need to reverse the attributes.
% See https://github.com/philss/floki/pull/467#discussion_r1225548333
{norm(Tag, Opts), maps:from_list(lists:reverse(Attrs)), []};
{norm(Tag, Opts), maps:from_list(lists:reverse(Attrs0)), []};
_ ->
{norm(Tag, Opts), Attrs, []}
{norm(Tag, Opts), Attrs0, []}
end;
norm(Tag, _Opts) when is_binary(Tag) ->
Tag;
Expand Down

0 comments on commit 000f4be

Please sign in to comment.