-
Notifications
You must be signed in to change notification settings - Fork 552
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 arrays that are sent in query strings #612
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find! I did look a little at Faraday's internals but missed this.
I agree that it's definitely weird that we'd encode the parameters ourselves or not depending on the type of the request, but this looks like a decent short-term fix.
As discussed in #608, we currently have a problem where Faraday deconstructs a query string that we encode and strips out any of the array index numbers that we added. It's not too clear on why it does this, but it appears to be built in at a pretty low level and hard to change. I spent a little time on this and it turns out that we can avoid the bad code by depending on Faraday's `params` accessor on a request instead of trying to do the encoding ourselves. Webmock has a pretty hard time detecting the difference, but you can see some before and after encoding here. Before: ``` I, [2017-12-06T17:41:23.083942 #36737] INFO -- : get http://localhost:12111/v1/invoices/upcoming?customer=cus_123&subscription_items%5B%5D%5Bplan%5D=gold&subscription_items%5B%5D%5Bquantity%5D=2 ``` After: ``` I, [2017-12-06T17:42:12.727752 #37158] INFO -- : get http://localhost:12111/v1/invoices/upcoming?customer=cus_123&subscription_items%5B0%5D%5Bplan%5D=gold&subscription_items%5B0%5D%5Bquantity%5D=2 ``` Honestly, some of this can still use a lot of cleanup: it's weird that we manually encode parameters ourselves for bodies, but not for queries; but I think this'll fix the problem for now. Fixes #608.
c06b258
to
2bc471d
Compare
Yeah totally. I think it should be relatively easy to clean this up too, and I could potentially take a stab on a follow up pull request. |
r? @ob-stripe Thanks for taking a look OB! Mind doing one more review pass? Thanks! |
lgtm 👍 |
FYI. this saved my life! It was really frustrated seeing that the same exact request params coming from the Stripe dashboard (while editing a subscription's items) wouldn't work went sent from my code ( using v. 3.8.0). Upgrading fixed it. 💥 Thanks guys |
@joebartels No worries! Glad it helped :) |
As discussed in #608, we currently have a problem where Faraday
deconstructs a query string that we encode and strips out any of the
array index numbers that we added. It's not too clear on why it does
this, but it appears to be built in at a pretty low level and hard to
change.
I spent a little time on this and it turns out that we can avoid the bad
code by depending on Faraday's
params
accessor on a request instead oftrying to do the encoding ourselves. Webmock has a pretty hard time
detecting the difference, but you can see some before and after encoding
here.
Before:
After:
Honestly, some of this can still use a lot of cleanup: it's weird that
we manually encode parameters ourselves for bodies, but not for queries;
but I think this'll fix the problem for now.
Fixes #608.