Navigation Menu

Skip to content

Commit

Permalink
Fix for error in parsing particular incorrect singletons.
Browse files Browse the repository at this point in the history
When the HTML parser attempts to parse tags that should be
singletons but are not, AND they have content, an exception
occurs:

  1> mochiweb_html:parse("<html><input><input>x</input></input></html>").
  ** exception error: no case clause matching
        	            {[],[{<<"input">>,[],[<<"x">>]},{<<"input">>,[],[]}]}
       in function  mochiweb_html:destack/2
       in call from mochiweb_html:tree/2
       in call from mochiweb_html:parse_tokens/1

This patch provides a fix.
  • Loading branch information
jkoops authored and etrepum committed Nov 10, 2010
1 parent ff2cdc9 commit bd0f1f0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/mochiweb_html.erl
Expand Up @@ -404,8 +404,8 @@ destack(TagName, Stack) when is_list(Stack) ->
{_, []} ->
%% Actually was a singleton
Stack;
{Pre, [{T1, A1, []} | Post1]} ->
[{T0, A0, [{T1, A1, lists:reverse(Pre)} | Post1]}
{Pre, [{T1, A1, Acc1} | Post1]} ->
[{T0, A0, [{T1, A1, Acc1 ++ lists:reverse(Pre)} | Post1]}
| Post0]
end;
_ ->
Expand Down Expand Up @@ -1250,5 +1250,15 @@ parse_broken_pi_test() ->
] },
mochiweb_html:parse(D0)),
ok.

parse_funny_singletons_test() ->
D0 = <<"<html><input><input>x</input></input></html>">>,
?assertEqual(
{<<"html">>, [], [
{ <<"input">>, [], [] },
{ <<"input">>, [], [ <<"x">> ] }
] },
mochiweb_html:parse(D0)),
ok.

-endif.

0 comments on commit bd0f1f0

Please sign in to comment.