-
Notifications
You must be signed in to change notification settings - Fork 548
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
Integer-index encode all arrays #674
Conversation
Changes all arrays from classic Rack encoding: ``` sh arr[]=...&arr[]=...&arr[]=... ``` To integer-indexed encoding: ``` sh arr[0]=...&arr[1]=...&arr[2]=... ``` We think that this should be tractable now that we've fully converted all endpoints over to the new AbstractAPIMethod infrastructure on the backend (although we should do a little more testing to make sure that all endpoints still work). As part of the conversion, we also remove any places that we were "spot encoding" to get required integer-indexed syntax. This should now all be built in.
# This method is invoked for any arrays being encoded and checks that if | ||
# the array contains all non-empty maps, that each of those maps must start | ||
# with the same key so that their boundaries can be properly encoded. | ||
def self.check_array_of_maps_start_keys!(arr) |
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.
This method was designed to check that arrays being encoded were compatible with Rack syntax for arrays of maps — now that we're using integer-indexed arrays everywhere, we don't need to check this anymore.
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.
Seems sane to me, beyond 👍ing that we should re-verify the changes are working fine against the server.
@@ -33,39 +33,11 @@ class UtilTest < Test::Unit::TestCase | |||
g: [], | |||
} | |||
assert_equal( | |||
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1&f=", | |||
"a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[0]=0&e[1]=1&f=", |
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.
Do we have a test that verifies an array of hashes too? {foo: [{bar: :a}, {bar: :b}]}
-> foo[0][bar]=a&foo[1][bar]=b
?
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.
Yeah! Check just a bit lower in "#url_encode should prepare strings for HTTP"
, and it seems to do a pretty good job.
LGTM |
Okay, I tested a few places where we've used non-integer-index arrays:
Numbers 1 and 2 worked fine, but number 3 didn't. Script: require "stripe"
Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
events = Stripe::Event.list(
limit: 10,
type: ["invoice.created", "invoice.updated"],
)
events.each do |event|
p event.type
end And result:
It looks like we encoded the parameter as expected, but the server balked at it — so we may still have a little more backend work to do before we can fully enable this. |
And nevermind — I used
Okay, I'm pretty comfortable with this change (and therefore the one in Java as well) then. @remi-stripe Anything else that you can think of? |
Changes all arrays from classic Rack encoding: ``` sh arr[]=...&arr[]=...&arr[]=... ``` To integer-indexed encoding: ``` sh arr[0]=...&arr[1]=...&arr[2]=... ``` See some additional background in: stripe/stripe-ruby#674
Changes all arrays from classic Rack encoding: ``` sh arr[]=...&arr[]=...&arr[]=... ``` To integer-indexed encoding: ``` sh arr[0]=...&arr[1]=...&arr[2]=... ``` See some additional background in: stripe/stripe-ruby#674
This looks good to me, especially as you explicitly tested multiple edge-cases! |
Thanks Remi! Let's go for it then. |
Released as 3.22.0. |
Changes all arrays from classic Rack encoding: ``` sh arr[]=...&arr[]=...&arr[]=... ``` To integer-indexed encoding: ``` sh arr[0]=...&arr[1]=...&arr[2]=... ``` See some additional background in: stripe/stripe-ruby#674
Changes all arrays from classic Rack encoding:
To integer-indexed encoding:
We think that this should be tractable now that we've fully converted
all endpoints over to the new AbstractAPIMethod infrastructure on the
backend (although we should do a little more testing to make sure that
all endpoints still work).
As part of the conversion, we also remove any places that we were "spot
encoding" to get required integer-indexed syntax. This should now all be
built in.
cc @stevene-stripe @zanker-stripe