Skip to content

Follow-up to 14101 #14132

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

Merged
merged 1 commit into from
Jun 25, 2025
Merged
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
21 changes: 5 additions & 16 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/formatters/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ defmodule RabbitMQ.CLI.Formatters.Json do
end

defp convert_erlang_strings(data) when is_list(data) do
# Only attempt Unicode conversion on proper lists of integers
if is_proper_list_of_integers?(data) do
try do
case :unicode.characters_to_binary(data, :utf8) do
binary when is_binary(binary) ->
# Successfully converted - it was a valid Unicode string
Expand All @@ -102,9 +101,10 @@ defmodule RabbitMQ.CLI.Formatters.Json do
# Conversion failed - not a Unicode string, process as regular list
Enum.map(data, &convert_erlang_strings/1)
end
else
# Not a proper list of integers, process as regular list
Enum.map(data, &convert_erlang_strings/1)
rescue
ArgumentError ->
# badarg exception - not valid character data, process as regular list
Enum.map(data, &convert_erlang_strings/1)
end
end

Expand All @@ -122,15 +122,4 @@ defmodule RabbitMQ.CLI.Formatters.Json do
end

defp convert_erlang_strings(data), do: data

# Check if data is a proper list containing only integers
defp is_proper_list_of_integers?([]), do: false # Empty lists are not strings
defp is_proper_list_of_integers?(data) when is_list(data) do
try do
Enum.all?(data, &is_integer/1)
rescue
_ -> false # Not a proper list or contains non-integers
end
end
defp is_proper_list_of_integers?(_), do: false
end
Loading