Skip to content

Commit 3addf94

Browse files
Be more defensive with certain responses
In Erlang historically (up until Erlang 17 or so) maps were expressed as lists of pairs, or proplists. This is still the case with some libraries today, including JSON generators. Therefore sometimes a RabbitMQ API response contains an empty array instead of an empty object (since in Erlang before maps, they were the same thing). This drive-by change avoids a Hashie hash being instantiated with an array, which throws an exception. This condition is increasingly rare to come by but still can be hit with some RabbitMQ HTTP API endpoints in certain conditions.
1 parent 29ecbce commit 3addf94

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/rabbitmq/http/client/response_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ def decode_response_body(body)
3131
def decode_resource_collection(response)
3232
collection = response.body.is_a?(Array) ? response.body : response.body.fetch('items')
3333

34-
collection.map { |i| Hashie::Mash.new(i) }
34+
collection.map do |i|
35+
if i == []
36+
Hashie::Mash.new()
37+
else
38+
Hashie::Mash.new(i)
39+
end
40+
end
3541
end
3642
end
3743
end

0 commit comments

Comments
 (0)