aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2007-02-04 16:04:40 +0000
committerAlexey Shchepin <alexey@process-one.net>2007-02-04 16:04:40 +0000
commit5b4e116cfdaada860c63c1d087906e5c07ef4c52 (patch)
tree18f42e3c95daf32cfd5bff843d6d0ede505a0ed2
parent* src/xml.erl: &apos; entity replaced by &#39; Should work more universaly (i... (diff)
* src/web/ejabberd_http.erl: Added separate version of
element_to_string for HTML encoding * src/xml.erl: Reverted previous change SVN Revision: 722
-rw-r--r--ChangeLog6
-rw-r--r--src/web/ejabberd_http.erl36
-rw-r--r--src/xml.erl2
3 files changed, 41 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index f3908d8bc..5b0615bf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-02-04 Alexey Shchepin <alexey@sevcom.net>
+
+ * 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 <mickael.remond@process-one.net>
* src/xml.erl: &apos; entity replaced by &#39; 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
+ $& -> "&amp;";
+ $< -> "&lt;";
+ $> -> "&gt;";
+ $" -> "&quot;";
+ $' -> "&#39;";
+ _ -> 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) ->
$< -> "&lt;";
$> -> "&gt;";
$" -> "&quot;";
- $' -> "&#39;";
+ $' -> "&apos;";
_ -> C
end || C <- S];
crypt(S) when is_binary(S) ->