Permalink
Browse files

Merge branch 'master' of github.com:mochi/mochiweb

  • Loading branch information...
2 parents 399eacd + 0a05238 commit 23dc11959affd9b0849c2ac0ff4200c1c82aa80c @etrepum etrepum committed Aug 12, 2017
Showing with 61 additions and 4 deletions.
  1. +9 −4 src/mochiweb_html.erl
  2. +6 −0 src/mochiweb_http.erl
  3. +46 −0 test/mochiweb_html_tests.erl
View
@@ -463,16 +463,21 @@ destack([{Tag, Attrs, Acc}]) ->
destack([{T1, A1, Acc1}, {T0, A0, Acc0} | Rest]) ->
destack([{T0, A0, [{T1, A1, lists:reverse(Acc1)} | Acc0]} | Rest]).
+is_singleton(<<"area">>) -> true;
+is_singleton(<<"base">>) -> true;
is_singleton(<<"br">>) -> true;
+is_singleton(<<"col">>) -> true;
+is_singleton(<<"embed">>) -> true;
is_singleton(<<"hr">>) -> true;
is_singleton(<<"img">>) -> true;
is_singleton(<<"input">>) -> true;
-is_singleton(<<"base">>) -> true;
-is_singleton(<<"meta">>) -> true;
+is_singleton(<<"keygen">>) -> true;
is_singleton(<<"link">>) -> true;
-is_singleton(<<"area">>) -> true;
+is_singleton(<<"meta">>) -> true;
is_singleton(<<"param">>) -> true;
-is_singleton(<<"col">>) -> true;
+is_singleton(<<"source">>) -> true;
+is_singleton(<<"track">>) -> true;
+is_singleton(<<"wbr">>) -> true;
is_singleton(_) -> false.
tokenize_data(B, S=#decoder{offset=O}) ->
View
@@ -97,6 +97,8 @@ request(Socket, Opts, Body) ->
{tcp_closed, _} ->
mochiweb_socket:close(Socket),
exit(normal);
+ {tcp_error, _, emsgsize} = Other ->
+ handle_invalid_msg_request(Other, Socket, Opts);
{ssl_closed, _} ->
mochiweb_socket:close(Socket),
exit(normal)
@@ -141,6 +143,10 @@ call_body({M, F}, Req) ->
call_body(Body, Req) ->
Body(Req).
+-spec handle_invalid_msg_request(term(), term(), term()) -> no_return().
+handle_invalid_msg_request(Msg, Socket, Opts) ->
+ handle_invalid_msg_request(Msg, Socket, Opts, {'GET', {abs_path, "/"}, {0,9}}, []).
+
-spec handle_invalid_msg_request(term(), term(), term(), term(), term()) -> no_return().
handle_invalid_msg_request(Msg, Socket, Opts, Request, RevHeaders) ->
case {Msg, r15b_workaround()} of
@@ -428,6 +428,52 @@ dumb_br_test() ->
{<<"div">>,[],[{<<"br">>, [], []}, {<<"br">>, [], []}, <<"z">>]},
mochiweb_html:parse("<div><br><br>z</br></br></div>")).
+empty_elements_test() ->
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"area">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<area>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"base">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<base>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"br">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<br>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"col">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<col>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"embed">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<embed>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"hr">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<hr>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"img">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<img>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"input">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<input>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"keygen">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<keygen>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"link">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<link>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"meta">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<meta>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"param">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<param>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"source">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<source>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"track">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<track>z</div>")),
+ ?assertEqual(
+ {<<"div">>,[],[<<"a">>,{<<"wbr">>,[],[]},<<"z">>]},
+ mochiweb_html:parse("<div>a<wbr>z</div>")).
php_test() ->
%% http://code.google.com/p/mochiweb/issues/detail?id=71

0 comments on commit 23dc119

Please sign in to comment.