Skip to content

Commit 7a5eb3b

Browse files
Merge pull request #12890 from rabbitmq/mergify/bp/v4.0.x/pr-12889
By @bpint: Fixes an exception in AMQP 0-9-1 exception (error) generator when input data includes non-ASCII characters (backport #12889)
2 parents f495a87 + b791974 commit 7a5eb3b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

deps/rabbit_common/src/rabbit_binary_generator.erl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,5 @@ lookup_amqp_exception(Other, Protocol) ->
228228
{ShouldClose, Code, Text, none}.
229229

230230
amqp_exception_explanation(Text, Expl) ->
231-
ExplBin = list_to_binary(Expl),
232-
CompleteTextBin = <<Text/binary, " - ", ExplBin/binary>>,
233-
if size(CompleteTextBin) > 255 -> <<CompleteTextBin:252/binary, "...">>;
234-
true -> CompleteTextBin
235-
end.
231+
LimitedText = io_lib:format("~ts - ~ts", [Text, Expl], [{chars_limit, 255}]),
232+
unicode:characters_to_binary(LimitedText).

deps/rabbit_common/test/unit_SUITE.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ groups() ->
4646
pid_decompose_compose,
4747
platform_and_version,
4848
frame_encoding_does_not_fail_with_empty_binary_payload,
49+
map_exception_does_not_fail_with_unicode_explaination_case1,
50+
map_exception_does_not_fail_with_unicode_explaination_case2,
4951
amqp_table_conversion,
5052
name_type,
5153
get_erl_path,
@@ -415,6 +417,20 @@ frame_encoding_does_not_fail_with_empty_binary_payload(_Config) ->
415417
]],
416418
ok.
417419

420+
map_exception_does_not_fail_with_unicode_explaination_case1(_Config) ->
421+
NonAsciiExplaination = "no queue 'non_ascii_name_😍_你好' in vhost '/'",
422+
rabbit_binary_generator:map_exception(0,
423+
#amqp_error{name = not_found, explanation = NonAsciiExplaination, method = 'queue.declare'},
424+
rabbit_framing_amqp_0_9_1),
425+
ok.
426+
427+
map_exception_does_not_fail_with_unicode_explaination_case2(_Config) ->
428+
NonAsciiExplaination = "no queue 'кролик 🐰' in vhost '/'",
429+
rabbit_binary_generator:map_exception(0,
430+
#amqp_error{name = not_found, explanation = NonAsciiExplaination, method = 'queue.declare'},
431+
rabbit_framing_amqp_0_9_1),
432+
ok.
433+
418434
amqp_table_conversion(_Config) ->
419435
assert_table(#{}, []),
420436
assert_table(#{<<"x-expires">> => 1000},

0 commit comments

Comments
 (0)