Skip to content

Fix 2D array parameter encoding#1846

Merged
jar-stripe merged 1 commit intomasterfrom
jar/fix-2d-array-encoding
Apr 1, 2026
Merged

Fix 2D array parameter encoding#1846
jar-stripe merged 1 commit intomasterfrom
jar/fix-2d-array-encoding

Conversation

@jar-stripe
Copy link
Copy Markdown
Contributor

@jar-stripe jar-stripe commented Apr 1, 2026

Why?

When encoding nested arrays (e.g. [[1, 2], [3, 4]]) as form parameters, the recursive call in flatten_params_array passed the parent key without the outer array index. This produced a[0]=1&a[1]=2 instead of the correct a[0][0]=1&a[0][1]=2, silently sending wrong data to the API.

What?

  • Fix one-line bug in lib/stripe/util.rb: append [#{i}] to the key before recursing into nested arrays
  • Update existing nested array test that was asserting the buggy behavior
  • Add new regression tests for 2D scalar arrays in both encode_parameters and flatten_params

See Also

Changelog

  • Fixes an issue encoding two-dimensional array request params where the SDK incorrectly flattens the array.

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
@jar-stripe jar-stripe marked this pull request as ready for review April 1, 2026 04:01
@jar-stripe jar-stripe requested a review from a team as a code owner April 1, 2026 04:01
@jar-stripe jar-stripe requested review from Copilot and prathmesh-stripe and removed request for a team April 1, 2026 04:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_array recursion 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_parameters and flatten_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.

@jar-stripe jar-stripe merged commit e76286e into master Apr 1, 2026
18 checks passed
@jar-stripe jar-stripe deleted the jar/fix-2d-array-encoding branch April 1, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants