diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index f1e7e6014..b5eb6de13 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -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 diff --git a/test/stripe/api_operations_test.rb b/test/stripe/api_operations_test.rb index 5d2954ae8..acaa81cb8 100644 --- a/test/stripe/api_operations_test.rb +++ b/test/stripe/api_operations_test.rb @@ -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")