From 69ec20b3b9ba98845c6c1b7f24c57b2c2386b8e1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 19 Aug 2015 21:45:35 +0200 Subject: [PATCH] mod_mam_mnesia: Ignore whitespace within Ignore the whitespace when a form field value is specified like this, for example: juliet@example.com --- mod_mam_mnesia/src/mod_mam_mnesia.erl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mod_mam_mnesia/src/mod_mam_mnesia.erl b/mod_mam_mnesia/src/mod_mam_mnesia.erl index 9016520..23c6d71 100644 --- a/mod_mam_mnesia/src/mod_mam_mnesia.erl +++ b/mod_mam_mnesia/src/mod_mam_mnesia.erl @@ -737,13 +737,13 @@ parse_form(Fields) when is_list(Fields) -> Parse = fun(#xmlel{name = <<"field">>, attrs = Attrs, - children = [#xmlel{name = <<"value">>, children = [Value]}]}, + children = [#xmlel{name = <<"value">>, children = Els}]}, Form) -> case xml:get_attr_s(<<"var">>, Attrs) of <<"FORM_TYPE">> -> Form; <<"start">> -> - CData = xml:get_cdata([Value]), + CData = get_cdata_without_whitespace(Els), case jlib:datetime_string_to_timestamp(CData) of undefined -> Form#mam_filter{start = error}; @@ -751,7 +751,7 @@ parse_form(Fields) when is_list(Fields) -> Form#mam_filter{start = Start} end; <<"end">> -> - CData = xml:get_cdata([Value]), + CData = get_cdata_without_whitespace(Els), case jlib:datetime_string_to_timestamp(CData) of undefined -> Form#mam_filter{fin = error}; @@ -759,7 +759,7 @@ parse_form(Fields) when is_list(Fields) -> Form#mam_filter{fin = End} end; <<"with">> -> - CData = xml:get_cdata([Value]), + CData = get_cdata_without_whitespace(Els), case jlib:string_to_jid(CData) of error -> Form#mam_filter{with = error}; @@ -856,6 +856,12 @@ check_request(#mam_query{index = Index, filter = Filter}) check_request(_Query) -> 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. %%--------------------------------------------------------------------