diff --git a/ChangeLog b/ChangeLog index f3908d8bc..5b0615bf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-02-04 Alexey Shchepin + + * src/web/ejabberd_http.erl: Added separate version of + element_to_string for HTML encoding + * src/xml.erl: Reverted previous change + 2007-02-04 Mickael Remond * src/xml.erl: ' entity replaced by ' Should work more diff --git a/src/web/ejabberd_http.erl b/src/web/ejabberd_http.erl index 24913de58..52a95d1cc 100644 --- a/src/web/ejabberd_http.erl +++ b/src/web/ejabberd_http.erl @@ -366,10 +366,10 @@ make_xhtml_output(State, Status, Headers, XHTML) -> Data = case lists:member(html, Headers) of true -> list_to_binary([?HTML_DOCTYPE, - xml:element_to_string(XHTML)]); + element_to_string(XHTML)]); _ -> list_to_binary([?XHTML_DOCTYPE, - xml:element_to_string(XHTML)]) + element_to_string(XHTML)]) end, Headers1 = case lists:keysearch("Content-Type", 1, Headers) of {value, _} -> @@ -449,6 +449,38 @@ parse_lang(Langs) -> "en" end. +element_to_string(El) -> + case El of + {xmlelement, Name, Attrs, Els} -> + if + Els /= [] -> + [$<, Name, attrs_to_list(Attrs), $>, + [element_to_string(E) || E <- Els], + $<, $/, Name, $>]; + true -> + [$<, Name, attrs_to_list(Attrs), $/, $>] + end; + {xmlcdata, CData} -> + crypt(CData) + end. + +attrs_to_list(Attrs) -> + [attr_to_list(A) || A <- Attrs]. + +attr_to_list({Name, Value}) -> + [$\s, crypt(Name), $=, $", crypt(Value), $"]. + +crypt(S) when is_list(S) -> + [case C of + $& -> "&"; + $< -> "<"; + $> -> ">"; + $" -> """; + $' -> "'"; + _ -> C + end || C <- S]; +crypt(S) when is_binary(S) -> + crypt(binary_to_list(S)). % Code below is taken (with some modifications) from the yaws webserver, which diff --git a/src/xml.erl b/src/xml.erl index 5689f30d1..888618867 100644 --- a/src/xml.erl +++ b/src/xml.erl @@ -111,7 +111,7 @@ crypt(S) when is_list(S) -> $< -> "<"; $> -> ">"; $" -> """; - $' -> "'"; + $' -> "'"; _ -> C end || C <- S]; crypt(S) when is_binary(S) ->