Skip to content

Commit

Permalink
Fix parsing of unescaped lt chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmzeeman committed Apr 26, 2012
1 parent 5305a4b commit 203499a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mochiweb_html.erl
Expand Up @@ -312,7 +312,8 @@ tokenize(B, S=#decoder{offset=O}) ->
{Tag, S1} = tokenize_literal(B, ?ADV_COL(S, 2)),
{S2, _} = find_gt(B, S1),
{{end_tag, Tag}, S2};
<<_:O/binary, "<", C, _/binary>> when ?IS_WHITESPACE(C) ->
<<_:O/binary, "<", C, _/binary>>
when ?IS_WHITESPACE(C); not ?IS_LITERAL_SAFE(C) ->
%% This isn't really strict HTML
{{data, Data, _Whitespace}, S1} = tokenize_data(B, ?INC_COL(S)),
{{data, <<$<, Data/binary>>, false}, S1};
Expand Down Expand Up @@ -1280,4 +1281,17 @@ parse_amp_test_() ->
[{<<"body">>,[],[<<"&">>]}]},
mochiweb_html:parse("<html><body>&</body></html>"))].

parse_unescaped_lt_test() ->
D1 = <<"<div> < < <a href=\"/\">Back</a></div>">>,
?assertEqual(
{<<"div">>, [], [<<" < < ">>, {<<"a">>, [{<<"href">>, <<"/">>}],
[<<"Back">>]}]},
mochiweb_html:parse(D1)),

D2 = <<"<div> << <a href=\"/\">Back</a></div>">>,
?assertEqual(
{<<"div">>, [], [<<" << ">>, {<<"a">>, [{<<"href">>, <<"/">>}],
[<<"Back">>]}]},
mochiweb_html:parse(D2)).

-endif.

0 comments on commit 203499a

Please sign in to comment.