aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/xml.erl14
2 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 34cc38f5e..31f888b52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2007-07-30 Mickael Remond <mickael.remond@process-one.net>
+ * src/xml.erl: Only wrap xmldata nodes in xml cdata "tag" if
+ bigger than 50 bytes. Shorter xmlcdata nodes will be escaped.
+
* src/tls/tls_drv.c: Sends the entire certificate chain (EJAB-209).
* src/acl.erl: Remove compilation warnings (EJAB-290).
diff --git a/src/xml.erl b/src/xml.erl
index 60c5d7934..2108d6920 100644
--- a/src/xml.erl
+++ b/src/xml.erl
@@ -20,6 +20,9 @@
get_path_s/2,
replace_tag_attr/3]).
+%% XML CDATA bigger than this will be enclosed in CDATA XML "tag"
+-define(CDATA_BINARY_THRESHOLD, 50).
+
element_to_string(El) ->
case El of
{xmlelement, Name, Attrs, Els} ->
@@ -31,13 +34,16 @@ element_to_string(El) ->
true ->
[$<, Name, attrs_to_list(Attrs), $/, $>]
end;
- {xmlcdata, CData} when list(CData) ->
- crypt(CData);
%% We do not crypt CDATA binary, but we enclose it in XML CDATA
- {xmlcdata, CData} when binary(CData) ->
+ %% if they are long enough to be worth it.
+ {xmlcdata, CData} when binary(CData), size(CData) > ?CDATA_BINARY_THRESHOLD ->
CDATA1 = <<"<![CDATA[">>,
CDATA2 = <<"]]>">>,
- concat_binary([CDATA1, CData, CDATA2])
+ concat_binary([CDATA1, CData, CDATA2]);
+ %% We crypt list and short binaries (implies a conversion to
+ %% list).
+ {xmlcdata, CData} ->
+ crypt(CData)
end.
attrs_to_list(Attrs) ->