From 10c68254aac8647c7bcf2a3d8f9523658eb828f7 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Thu, 22 May 2008 20:30:57 +0000 Subject: Updated MochiWeb in trunk to r73. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@659244 13f79535-47bb-0310-9956-ffa450edef68 --- src/mochiweb/mochiweb_html.erl | 89 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) (limited to 'src/mochiweb/mochiweb_html.erl') diff --git a/src/mochiweb/mochiweb_html.erl b/src/mochiweb/mochiweb_html.erl index 3c7f9dfc..0ac4826e 100644 --- a/src/mochiweb/mochiweb_html.erl +++ b/src/mochiweb/mochiweb_html.erl @@ -35,7 +35,7 @@ -define(IS_LITERAL_SAFE(C), ((C >= $A andalso C =< $Z) orelse (C >= $a andalso C =< $z) orelse (C >= $0 andalso C =< $9))). - + -record(decoder, {line=1, column=1, offset=0}). @@ -202,7 +202,7 @@ attrs_to_html([{K, V} | Rest], Acc) -> attrs_to_html(Rest, [[<<" ">>, escape(K), <<"=\"">>, escape_attr(V), <<"\"">>] | Acc]). - + test_escape() -> <<"&quot;\"word <<up!&quot;">> = escape(<<""\"word <>), @@ -299,6 +299,14 @@ test_tokens() -> tokens(<<"">>), [{comment, <<"[if lt IE 7]>\n\n>}] = tokens(<<"">>), + [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}], false}, + {data, <<" A= B <= C ">>, false}, + {end_tag, <<"script">>}] = + tokens(<<"">>), + [{start_tag, <<"textarea">>, [], false}, + {data, <<"">>, false}, + {end_tag, <<"textarea">>}] = + tokens(<<"">>), ok. tokens(B, S=#decoder{offset=O}, Acc) -> @@ -307,9 +315,30 @@ tokens(B, S=#decoder{offset=O}, Acc) -> lists:reverse(Acc); _ -> {Tag, S1} = tokenize(B, S), - tokens(B, S1, [Tag | Acc]) + case parse_flag(Tag) of + script -> + {Tag2, S2} = tokenize_script(B, S1), + tokens(B, S2, [Tag2, Tag | Acc]); + textarea -> + {Tag2, S2} = tokenize_textarea(B, S1), + tokens(B, S2, [Tag2, Tag | Acc]); + none -> + tokens(B, S1, [Tag | Acc]) + end end. +parse_flag({start_tag, B, _, false}) -> + case string:to_lower(binary_to_list(B)) of + "script" -> + script; + "textarea" -> + textarea; + _ -> + none + end; +parse_flag(_) -> + none. + tokenize(B, S=#decoder{offset=O}) -> case B of <<_:O/binary, "