From 325e1103762b9f1dc12afa1e74c2490ff0525353 Mon Sep 17 00:00:00 2001 From: Andy Jeffries Date: Mon, 22 Jan 2024 10:00:59 +0000 Subject: [PATCH] Don't mutate parameters in a Command line interface to a user's defaults. Syntax: 'defaults' [-currentHost | -host ] followed by one of the following: read shows all defaults read shows defaults for given domain read shows defaults for given domain, key read-type shows the type for the given domain, key write writes domain (overwrites existing) write writes key for domain rename renames old_key to new_key delete deletes domain delete deletes key in domain delete-all deletes the domain from all containers delete-all Key> deletes key in domain from all containers import writes the plist at path to domain import - writes a plist from stdin to domain export saves domain as a binary plist to path export - writes domain as an xml plist to stdout domains lists all domains find lists all entries containing word help print this help is ( | -app | -globalDomain ) or a path to a file omitting the '.plist' extension is one of: -string -data -int[eger] -float -bool[ean] (true | false | yes | no) -date -array ... -array-add ... -dict ... -dict-add ... Proc --- CHANGELOG.md | 6 ++++++ lib/flexirest/request.rb | 2 ++ lib/flexirest/version.rb | 2 +- spec/lib/request_spec.rb | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e387c9f..ef0b355 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.12.2 + +Bugfix: + +- Changing the parameters in a `defaults` option to a mapping shouldn't mutate the parameters, meaning that retries should get the same as the original parameters (thanks to vskbjrn for the bug report) + ## 1.12.1 Bugfix: diff --git a/lib/flexirest/request.rb b/lib/flexirest/request.rb index 62f761a..b676a49 100644 --- a/lib/flexirest/request.rb +++ b/lib/flexirest/request.rb @@ -344,6 +344,8 @@ def prepare_params params = {id:params} end + params = params.dup + # Format includes parameter for jsonapi if proxy == :json_api JsonAPIProxy::Request::Params.translate(params, @object._include_associations) diff --git a/lib/flexirest/version.rb b/lib/flexirest/version.rb index 1ca4209..2fb7f60 100644 --- a/lib/flexirest/version.rb +++ b/lib/flexirest/version.rb @@ -1,3 +1,3 @@ module Flexirest - VERSION = "1.12.1" + VERSION = "1.12.2" end diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb index 62c946f..47ac10c 100644 --- a/spec/lib/request_spec.rb +++ b/spec/lib/request_spec.rb @@ -173,6 +173,13 @@ def inner_call(name, response) get :second_call, "/second_call" end + class SimpleRetryingExampleClient < Flexirest::Base + base_url "http://www.example.com" + get :all, "/objects", defaults: proc { |params| { type: params.delete(:object_type) } } + + after_request -> (name, response) { raise Flexirest::CallbackRetryRequestException.new } + end + class LazyLoadedExampleClient < ExampleClient base_url "http://www.example.com" lazy_load! @@ -1395,6 +1402,13 @@ def verbose ; false ; end expect(RetryingExampleClient.retries).to eq(2) end + it "shouldn't destructively change params before retrying" do + stub_request(:get, "http://www.example.com/objects?type=foo"). + to_return(status: 200, body: "", headers: {}) + SimpleRetryingExampleClient.all(object_type: 'foo') + + expect(WebMock).to have_requested(:get, "www.example.com/objects?type=foo").twice + end context "Direct URL requests" do class SameServerExampleClient < Flexirest::Base