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

Update normalize_opts to use dup instead of clone. #985

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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