Skip to content

Commit

Permalink
Use correct AMQP filter expression string modifier prefix
Browse files Browse the repository at this point in the history
Section 4.1.1 of AMQP Filter Expressions Working Draft 09
defines `&` (ampersand) instead of `$` (dollar) as the string modifier prefix.
  • Loading branch information
ansd committed Dec 11, 2024
1 parent fc4a691 commit 9d8ae14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions deps/rabbit/src/rabbit_amqp_filtex.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ validate_app_props(_, _) ->
error.

%% [filtex-v1.0-wd09 4.1.1]
parse_string_modifier_prefix(<<"$s:", Suffix/binary>>) ->
parse_string_modifier_prefix(<<"&s:", Suffix/binary>>) ->
{suffix, size(Suffix), Suffix};
parse_string_modifier_prefix(<<"$p:", Prefix/binary>>) ->
parse_string_modifier_prefix(<<"&p:", Prefix/binary>>) ->
{prefix, size(Prefix), Prefix};
parse_string_modifier_prefix(<<"$$", _/binary>> = String) ->
parse_string_modifier_prefix(<<"&&", _/binary>> = String) ->
%% "Escape prefix for case-sensitive matching of a string starting with ‘&’"
string:slice(String, 1);
parse_string_modifier_prefix(<<"$", _/binary>> = String) ->
parse_string_modifier_prefix(<<"&", _/binary>> = String) ->
throw({?MODULE, invalid_reference_field_value, String});
parse_string_modifier_prefix(String) ->
String.
Expand Down
32 changes: 16 additions & 16 deletions deps/rabbit/test/amqp_filtex_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ string_modifier(Config) ->
ok = amqp10_client:send_msg(
Sender,
amqp10_msg:set_properties(
#{subject => <<"$Hello">>,
#{subject => <<"&Hello">>,
reply_to_group_id => <<"xyz 5">>},
amqp10_msg:new(<<"t3">>, <<"m3">>))),

Expand All @@ -561,17 +561,17 @@ string_modifier(Config) ->
flush(sent),

PropsFilter1 = [
{{symbol, <<"to">>}, {utf8, <<"$p:abc ">>}},
{{symbol, <<"reply-to">>}, {utf8, <<"$p:abc">>}},
{{symbol, <<"subject">>}, {utf8, <<"$p:ab">>}},
{{symbol, <<"group-id">>}, {utf8, <<"$p:a">>}},
{{symbol, <<"reply-to-group-id">>}, {utf8, <<"$s:5">>}},
{{symbol, <<"correlation-id">>}, {utf8, <<"$s:abc 7">>}},
{{symbol, <<"message-id">>}, {utf8, <<"$p:abc 6">>}}
{{symbol, <<"to">>}, {utf8, <<"&p:abc ">>}},
{{symbol, <<"reply-to">>}, {utf8, <<"&p:abc">>}},
{{symbol, <<"subject">>}, {utf8, <<"&p:ab">>}},
{{symbol, <<"group-id">>}, {utf8, <<"&p:a">>}},
{{symbol, <<"reply-to-group-id">>}, {utf8, <<"&s:5">>}},
{{symbol, <<"correlation-id">>}, {utf8, <<"&s:abc 7">>}},
{{symbol, <<"message-id">>}, {utf8, <<"&p:abc 6">>}}
],
AppPropsFilter1 = [
{{utf8, <<"k1">>}, {utf8, <<"$s: 8">>}},
{{utf8, <<"k2">>}, {utf8, <<"$p:abc ">>}}
{{utf8, <<"k1">>}, {utf8, <<"&s: 8">>}},
{{utf8, <<"k2">>}, {utf8, <<"&p:abc ">>}}
],
Filter1 = #{?DESCRIPTOR_NAME_PROPERTIES_FILTER => {map, PropsFilter1},
?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER => {map, AppPropsFilter1},
Expand All @@ -590,7 +590,7 @@ string_modifier(Config) ->
%% Same filters as before except for subject which shouldn't match anymore.
PropsFilter2 = lists:keyreplace(
{symbol, <<"subject">>}, 1, PropsFilter1,
{{symbol, <<"subject">>}, {utf8, <<"$s:xxxxxxxxxxxxxx">>}}),
{{symbol, <<"subject">>}, {utf8, <<"&s:xxxxxxxxxxxxxx">>}}),
Filter2 = #{?DESCRIPTOR_NAME_PROPERTIES_FILTER => {map, PropsFilter2},
?DESCRIPTOR_NAME_APPLICATION_PROPERTIES_FILTER => {map, AppPropsFilter1},
<<"rabbitmq:stream-offset-spec">> => <<"first">>},
Expand All @@ -601,7 +601,7 @@ string_modifier(Config) ->
ok = assert_no_msg_received(?LINE),
ok = detach_link_sync(Receiver2),

PropsFilter3 = [{{symbol, <<"reply-to-group-id">>}, {utf8, <<"$s: 5">>}}],
PropsFilter3 = [{{symbol, <<"reply-to-group-id">>}, {utf8, <<"&s: 5">>}}],
Filter3 = #{?DESCRIPTOR_NAME_PROPERTIES_FILTER => {map, PropsFilter3},
<<"rabbitmq:stream-offset-spec">> => <<"first">>},
{ok, Receiver3} = amqp10_client:attach_receiver_link(
Expand All @@ -618,8 +618,8 @@ string_modifier(Config) ->
end,
ok = detach_link_sync(Receiver3),

%% '$$" is the escape prefix for case-sensitive matching of a string starting with ‘&’
PropsFilter4 = [{{symbol, <<"subject">>}, {utf8, <<"$$Hello">>}}],
%% '&&" is the escape prefix for case-sensitive matching of a string starting with ‘&’
PropsFilter4 = [{{symbol, <<"subject">>}, {utf8, <<"&&Hello">>}}],
Filter4 = #{?DESCRIPTOR_NAME_PROPERTIES_FILTER => {map, PropsFilter4},
<<"rabbitmq:stream-offset-spec">> => <<"first">>},
{ok, Receiver4} = amqp10_client:attach_receiver_link(
Expand All @@ -629,12 +629,12 @@ string_modifier(Config) ->
?assertEqual([<<"m3">>], amqp10_msg:body(R4M3)),
ok = detach_link_sync(Receiver4),

%% Starting the reference field value with $ is invalid without using a valid modifier
%% Starting the reference field value with & is invalid without using a valid modifier
%% prefix is invalid.
%% RabbitMQ should exclude this filter in its reply attach frame because
%% "the sending endpoint [RabbitMQ] sets the filter actually in place".
%% Hence, no filter expression is actually in place and we should receive all messages.
PropsFilter5 = [{{symbol, <<"subject">>}, {utf8, <<"$Hello">>}}],
PropsFilter5 = [{{symbol, <<"subject">>}, {utf8, <<"&Hello">>}}],
Filter5 = #{?DESCRIPTOR_NAME_PROPERTIES_FILTER => {map, PropsFilter5},
<<"rabbitmq:stream-offset-spec">> => <<"first">>},
{ok, Receiver5} = amqp10_client:attach_receiver_link(
Expand Down

0 comments on commit 9d8ae14

Please sign in to comment.