Skip to content

Commit

Permalink
Update normalize_opts to use dup instead of clone. (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcr-stripe authored Jun 29, 2021
1 parent 19da551 commit 90223fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def self.normalize_opts(opts)
{ 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
Expand Down
8 changes: 8 additions & 0 deletions test/stripe/api_operations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def self.protected_fields
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")
Expand Down

0 comments on commit 90223fa

Please sign in to comment.