From e4612476bd7a5e7268385b190addb6780f79902c Mon Sep 17 00:00:00 2001 From: Helen Ye Date: Wed, 13 Nov 2024 13:53:03 -0500 Subject: [PATCH] Fix incorrect key in param encoding --- lib/stripe/util.rb | 2 +- test/stripe/util_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index 44817888..d03e758c 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -259,7 +259,7 @@ def self.flatten_params_array(value, api_mode, calculated_key) if elem.is_a?(Hash) result += flatten_params(elem, api_mode, "#{calculated_key}[#{i}]") elsif elem.is_a?(Array) - result += flatten_params_array(elem, calculated_key, api_mode) + result += flatten_params_array(elem, api_mode, calculated_key) else result << if api_mode == :v2 [calculated_key, elem] diff --git a/test/stripe/util_test.rb b/test/stripe/util_test.rb index 900c37fb..8e5f5608 100644 --- a/test/stripe/util_test.rb +++ b/test/stripe/util_test.rb @@ -16,6 +16,7 @@ class UtilTest < Test::Unit::TestCase # NOTE: the empty hash won't even show up in the request g: [], + } assert_equal( "a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[0]=0&e[1]=1&f=", @@ -23,6 +24,16 @@ class UtilTest < Test::Unit::TestCase ) end + should "correctly represent nested arrays" do + params = { + a: [[foo: "bar", baz: "qux"]], + } + assert_equal( + "a[0][foo]=bar&a[0][baz]=qux", + Stripe::Util.encode_parameters(params, :v1) + ) + end + should "use correct array expansion for v2 query params" do params = { d: { a: "a", b: "b" },