Merged
Conversation
When encoding nested arrays (e.g. [[1, 2], [3, 4]]), the recursive call
in flatten_params_array was passing the parent key without the outer
array index, producing `a[0]=1&a[1]=2` instead of `a[0][0]=1&a[0][1]=2`.
Fix by appending [#{i}] to the key before recursing into nested arrays.
Also update the existing nested array test which was asserting the buggy
behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect form-encoding of nested (2D) arrays in Stripe::Util by ensuring the outer array index is preserved during recursive flattening, and adds/updates tests to prevent regressions when encoding and flattening 2D scalar arrays.
Changes:
- Fix
flatten_params_arrayrecursion to append the current outer array index to the calculated key when descending into nested arrays. - Update the existing nested-array encoding test to assert the correct (previously broken) behavior.
- Add regression tests covering 2D scalar arrays for both
encode_parametersandflatten_params.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/stripe/util.rb |
Fixes nested array key calculation when recursively flattening array parameters. |
test/stripe/util_test.rb |
Updates/extends tests to validate correct 2D array encoding/flattening with indices. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prathmesh-stripe
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
When encoding nested arrays (e.g.
[[1, 2], [3, 4]]) as form parameters, the recursive call inflatten_params_arraypassed the parent key without the outer array index. This produceda[0]=1&a[1]=2instead of the correcta[0][0]=1&a[0][1]=2, silently sending wrong data to the API.What?
lib/stripe/util.rb: append[#{i}]to the key before recursing into nested arraysencode_parametersandflatten_paramsSee Also
Changelog