Skip to content

Commit

Permalink
Fix incorrect key in param encoding (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
helenye-stripe authored Nov 15, 2024
1 parent c4d0746 commit 56b9950
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 11 additions & 0 deletions test/stripe/util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ 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=",
Stripe::Util.encode_parameters(params, :v1)
)
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" },
Expand Down

0 comments on commit 56b9950

Please sign in to comment.