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 encoding of list params for bank accounts and cards #633

Merged
merged 1 commit into from
Jul 24, 2018

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Jul 24, 2018

Fixes a bug discovered in #632 whereby because we were manually adding a
filter like ?object=bank_account to the end of paths, we'd clash with
the form package's attempt at an encoding if both came into play. This
would have the effect of producing an invalid URL like this:

/accounts/acc_xxxxxx/external_accounts?object=bank_account?limit=1&starting_after=ba_xxxxxx

(Note the multiple ?s in the query string.)

Here we stop manually adding filters to URL paths and move them into a
custom AppendTo override for the form package. Bank accounts and
cards were the only places that we were doing this, so only they were
affected.

We also add tests to make sure that we're doing the right thing.

Fixes #632.

r? @remi-stripe
cc @stripe/api-libraries

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

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

Damn, I never assumed that change could have broken the API that way. Thanks for figuring it out.

Added 2 comments about the test suite

card_test.go Outdated

// Adds `object` for customer (this will hit the sources endpoint)
{
params := &CardListParams{Account: String("acct_123")}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Customer: String("cus_123") instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops! Thank you. Fixed.

form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bank_account"}, body.Get("object"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should you be testing Account and Customer like you do for cards?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I skipped it because the same conditional branch just adds object regardless of the circumstances, but I guess it can't hurt to be explicit. Broke it into two test cases like cards.

Fixes a bug discovered in #632 whereby because we were manually adding a
filter like `?object=bank_account` to the end of paths, we'd clash with
the `form` package's attempt at an encoding if both came into play. This
would have the effect of producing an invalid URL like this:

```
/accounts/acc_xxxxxx/external_accounts?object=bank_account?limit=1&starting_after=ba_xxxxxx
```

(Note the multiple `?`s in the query string.)

Here we stop manually adding filters to URL paths and move them into a
custom `AppendTo` override for the `form` package. Bank accounts and
cards were the only places that we were doing this, so only they were
affected.

We also add tests to make sure that we're doing the right thing.
@brandur-stripe brandur-stripe force-pushed the brandur-fix-list-params-encoding branch from 8420692 to d90d28b Compare July 24, 2018 20:02
@brandur-stripe brandur-stripe merged commit fe659fc into master Jul 24, 2018
@brandur-stripe brandur-stripe deleted the brandur-fix-list-params-encoding branch July 24, 2018 20:35
nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
Bumps [sorbet](https://github.com/sorbet/sorbet) from 0.5.10274 to 0.5.10286.
- [Release notes](https://github.com/sorbet/sorbet/releases)
- [Commits](https://github.com/sorbet/sorbet/commits)

---
updated-dependencies:
- dependency-name: sorbet
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants