diff --git a/deps/rabbit/src/rabbit_amqp_filtex.erl b/deps/rabbit/src/rabbit_amqp_filtex.erl index bcdd289e4723..7ea57b2c386f 100644 --- a/deps/rabbit/src/rabbit_amqp_filtex.erl +++ b/deps/rabbit/src/rabbit_amqp_filtex.erl @@ -119,9 +119,16 @@ validate0(Descriptor, KVList0) when KVList = lists:map(fun({{utf8, Key}, {utf8, String}}) -> {Key, parse_string_modifier_prefix(String)}; ({{utf8, Key}, TaggedVal}) -> - {Key, unwrap(TaggedVal)} + {Key, unwrap(TaggedVal)}; + (_) -> + invalid_filter end, KVList0), - {ok, {application_properties, KVList}}; + case lists:member(invalid_filter, KVList) of + false -> + {ok, {application_properties, KVList}}; + true -> + error + end; validate0(_, _) -> error. diff --git a/deps/rabbit/test/amqp_filtex_SUITE.erl b/deps/rabbit/test/amqp_filtex_SUITE.erl index 51469821a83b..88e6c5ef5cca 100644 --- a/deps/rabbit/test/amqp_filtex_SUITE.erl +++ b/deps/rabbit/test/amqp_filtex_SUITE.erl @@ -32,7 +32,8 @@ all() -> [ - {group, cluster_size_1} + {group, cluster_size_1}, + {group, filter_validation} ]. groups() -> @@ -44,6 +45,10 @@ groups() -> multiple_sections, filter_few_messages_from_many, string_modifier + ]}, + {filter_validation, [shuffle], + [ + invalid_application_property_filter ]} ]. @@ -579,6 +584,20 @@ string_modifier(Config) -> ok = end_session_sync(Session), ok = close_connection_sync(Connection). +invalid_application_property_filter(_Config) -> + %% the only expression is invalid + ?assertEqual(error, + rabbit_amqp_filtex:validate( + {described,{symbol,?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER}, + {map,[{{symbol,<<"subject">>},{utf8,<<"var">>}}]}})), + + %% one expressions is valid but another one is not + ?assertEqual(error, + rabbit_amqp_filtex:validate( + {described,{symbol,?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER}, + {map,[{{utf8, <<"valid">>}, {symbol, <<"no match">>}}, + {{symbol,<<"subject">>}, {utf8,<<"var">>}}]}})). + %% ------------------------------------------------------------------- %% Helpers %% -------------------------------------------------------------------