Update normalize_opts to use dup instead of clone. (#985)

This commit is contained in:
Dominic Charley-Roy 2021-06-29 17:04:56 -04:00 committed by GitHub
parent 19da5510df
commit 90223fa06b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -208,7 +208,9 @@ module Stripe
{ api_key: opts }
when Hash
check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key)
opts.clone
# Explicitly use dup here instead of clone to avoid preserving freeze
# state on input params.
opts.dup
else
raise TypeError, "normalize_opts expects a string or a hash"
end

View File

@ -23,6 +23,14 @@ module Stripe
assert_equal("bar", resource.foo)
end
should "handle a frozen set of opts" do
stub_request(:post, "#{Stripe.api_base}/v1/updateableresources/id")
.with(body: { foo: "bar" })
.to_return(body: JSON.generate(foo: "bar"))
resource = UpdateableResource.update("id", { foo: "bar" }, {}.freeze)
assert_equal("bar", resource.foo)
end
should "error on protected fields" do
e = assert_raises do
UpdateableResource.update("id", protected: "bar")