From c6097eb80da50c0d850d06777ddc67c62360f465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Rigart?= Date: Fri, 2 Aug 2024 19:27:18 +0200 Subject: [PATCH 1/2] fix normalized_keys method when using a nested payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michaël Rigart --- lib/httparty/hash_conversions.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/httparty/hash_conversions.rb b/lib/httparty/hash_conversions.rb index 270effe3..fb7c9faa 100644 --- a/lib/httparty/hash_conversions.rb +++ b/lib/httparty/hash_conversions.rb @@ -54,11 +54,9 @@ def self.normalize_keys(key, value) stack.each do |parent, hash| hash.each do |child_key, child_value| if child_value.respond_to?(:to_hash) - stack << ["#{parent}[#{child_key}]", child_value.to_hash] + normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten elsif child_value.respond_to?(:to_ary) - child_value.to_ary.each do |v| - normalized_keys << normalize_keys("#{parent}[#{child_key}][]", v).flatten - end + normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value) else normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten end From ed744fbaa71d0641b797abfe70143b21d3bbd22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Rigart?= Date: Fri, 16 Aug 2024 11:58:31 +0200 Subject: [PATCH 2/2] fix key normalization for deeply nested payload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michaël Rigart --- lib/httparty/hash_conversions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/httparty/hash_conversions.rb b/lib/httparty/hash_conversions.rb index fb7c9faa..a888db0e 100644 --- a/lib/httparty/hash_conversions.rb +++ b/lib/httparty/hash_conversions.rb @@ -54,9 +54,9 @@ def self.normalize_keys(key, value) stack.each do |parent, hash| hash.each do |child_key, child_value| if child_value.respond_to?(:to_hash) - normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten + normalized_keys += normalize_keys("#{parent}[#{child_key}]", child_value) elsif child_value.respond_to?(:to_ary) - normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value) + normalized_keys += normalize_keys("#{parent}[#{child_key}]", child_value) else normalized_keys << normalize_keys("#{parent}[#{child_key}]", child_value).flatten end