Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect key in param encoding #1488

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading