@@ -92,8 +92,7 @@ defmodule RabbitMQ.CLI.Formatters.Json do
92
92
end
93
93
94
94
defp convert_erlang_strings ( data ) when is_list ( data ) do
95
- # Only attempt Unicode conversion on proper lists of integers
96
- if is_proper_list_of_integers? ( data ) do
95
+ try do
97
96
case :unicode . characters_to_binary ( data , :utf8 ) do
98
97
binary when is_binary ( binary ) ->
99
98
# Successfully converted - it was a valid Unicode string
@@ -102,9 +101,10 @@ defmodule RabbitMQ.CLI.Formatters.Json do
102
101
# Conversion failed - not a Unicode string, process as regular list
103
102
Enum . map ( data , & convert_erlang_strings / 1 )
104
103
end
105
- else
106
- # Not a proper list of integers, process as regular list
107
- Enum . map ( data , & convert_erlang_strings / 1 )
104
+ rescue
105
+ ArgumentError ->
106
+ # badarg exception - not valid character data, process as regular list
107
+ Enum . map ( data , & convert_erlang_strings / 1 )
108
108
end
109
109
end
110
110
@@ -122,15 +122,4 @@ defmodule RabbitMQ.CLI.Formatters.Json do
122
122
end
123
123
124
124
defp convert_erlang_strings ( data ) , do: data
125
-
126
- # Check if data is a proper list containing only integers
127
- defp is_proper_list_of_integers? ( [ ] ) , do: false # Empty lists are not strings
128
- defp is_proper_list_of_integers? ( data ) when is_list ( data ) do
129
- try do
130
- Enum . all? ( data , & is_integer / 1 )
131
- rescue
132
- _ -> false # Not a proper list or contains non-integers
133
- end
134
- end
135
- defp is_proper_list_of_integers? ( _ ) , do: false
136
125
end
0 commit comments