Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an exception in AMQP 0-9-1 exception (error) generator when input data includes non-ASCII characters #12888

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions deps/rabbit_common/src/rabbit_binary_generator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,5 @@ lookup_amqp_exception(Other, Protocol) ->
{ShouldClose, Code, Text, none}.

amqp_exception_explanation(Text, Expl) ->
ExplBin = list_to_binary(Expl),
CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>,
if size(CompleteTextBin) > 255 -> <<CompleteTextBin:252/binary, "...">>;
true -> CompleteTextBin
end.
LimitedText = io_lib:format("~ts - ~ts", [Text, Expl], [{chars_limit, 255}]),
unicode:characters_to_binary(LimitedText).
8 changes: 8 additions & 0 deletions deps/rabbit_common/test/unit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ groups() ->
pid_decompose_compose,
platform_and_version,
frame_encoding_does_not_fail_with_empty_binary_payload,
map_exception_does_not_fail_with_unicode_explaination,
amqp_table_conversion,
name_type,
get_erl_path,
Expand Down Expand Up @@ -415,6 +416,13 @@ frame_encoding_does_not_fail_with_empty_binary_payload(_Config) ->
]],
ok.

map_exception_does_not_fail_with_unicode_explaination(_Config) ->
NonAsciiExplaination = "no queue 'non_ascii_name_😍_你好' in vhost '/'",
rabbit_binary_generator:map_exception(0,
#amqp_error{name = not_found, explanation = NonAsciiExplaination, method = 'queue.declare'},
rabbit_framing_amqp_0_9_1),
ok.

amqp_table_conversion(_Config) ->
assert_table(#{}, []),
assert_table(#{<<"x-expires">> => 1000},
Expand Down