mod_mam_mnesia: Ignore whitespace within <value/>

Ignore the whitespace when a form field value is specified like this,
for example:

	<value>
	  juliet@example.com
	</value>
This commit is contained in:
Holger Weiss 2015-08-19 21:45:35 +02:00
parent 6316b0f097
commit 69ec20b3b9
1 changed files with 10 additions and 4 deletions

View File

@ -737,13 +737,13 @@ parse_form(Fields) when is_list(Fields) ->
Parse = Parse =
fun(#xmlel{name = <<"field">>, fun(#xmlel{name = <<"field">>,
attrs = Attrs, attrs = Attrs,
children = [#xmlel{name = <<"value">>, children = [Value]}]}, children = [#xmlel{name = <<"value">>, children = Els}]},
Form) -> Form) ->
case xml:get_attr_s(<<"var">>, Attrs) of case xml:get_attr_s(<<"var">>, Attrs) of
<<"FORM_TYPE">> -> <<"FORM_TYPE">> ->
Form; Form;
<<"start">> -> <<"start">> ->
CData = xml:get_cdata([Value]), CData = get_cdata_without_whitespace(Els),
case jlib:datetime_string_to_timestamp(CData) of case jlib:datetime_string_to_timestamp(CData) of
undefined -> undefined ->
Form#mam_filter{start = error}; Form#mam_filter{start = error};
@ -751,7 +751,7 @@ parse_form(Fields) when is_list(Fields) ->
Form#mam_filter{start = Start} Form#mam_filter{start = Start}
end; end;
<<"end">> -> <<"end">> ->
CData = xml:get_cdata([Value]), CData = get_cdata_without_whitespace(Els),
case jlib:datetime_string_to_timestamp(CData) of case jlib:datetime_string_to_timestamp(CData) of
undefined -> undefined ->
Form#mam_filter{fin = error}; Form#mam_filter{fin = error};
@ -759,7 +759,7 @@ parse_form(Fields) when is_list(Fields) ->
Form#mam_filter{fin = End} Form#mam_filter{fin = End}
end; end;
<<"with">> -> <<"with">> ->
CData = xml:get_cdata([Value]), CData = get_cdata_without_whitespace(Els),
case jlib:string_to_jid(CData) of case jlib:string_to_jid(CData) of
error -> error ->
Form#mam_filter{with = error}; Form#mam_filter{with = error};
@ -856,6 +856,12 @@ check_request(#mam_query{index = Index, filter = Filter})
check_request(_Query) -> check_request(_Query) ->
ok. ok.
-spec get_cdata_without_whitespace([xmlel() | cdata()]) -> binary().
get_cdata_without_whitespace(Els) ->
CData = xml:get_cdata(Els),
re:replace(CData, <<"[[:space:]]">>, <<"">>, [global, {return, binary}]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Send responses. %% Send responses.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------