From 4145c741a7a25728b3a459068a21eafa0164e397 Mon Sep 17 00:00:00 2001 From: Daniel Arnold Date: Wed, 4 Jun 2025 13:43:09 -0400 Subject: [PATCH 1/3] dup params to avoid modifying input hash, bump version --- lib/emailable/client.rb | 9 +++++---- lib/emailable/version.rb | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/emailable/client.rb b/lib/emailable/client.rb index e738740..db2b78f 100644 --- a/lib/emailable/client.rb +++ b/lib/emailable/client.rb @@ -17,8 +17,9 @@ def initialize end def request(method, endpoint, params = {}) - api_key = params.delete(:api_key) - access_token = params.delete(:access_token) + req_params = params.dup + api_key = req_params.delete(:api_key) + access_token = req_params.delete(:access_token) uri = URI("#{@base_url}/#{endpoint}") headers = { @@ -30,12 +31,12 @@ def request(method, endpoint, params = {}) tries ||= 3 http_response = if method == :get - uri.query = URI.encode_www_form(params) unless params.empty? + uri.query = URI.encode_www_form(req_params) unless req_params.empty? request = Net::HTTP::Get.new(uri, headers) @connection.request(request) elsif method == :post request = Net::HTTP::Post.new(uri, headers) - request.body = params.to_json + request.body = req_params.to_json @connection.request(request) end diff --git a/lib/emailable/version.rb b/lib/emailable/version.rb index 3d51d7d..2a0f9d9 100644 --- a/lib/emailable/version.rb +++ b/lib/emailable/version.rb @@ -1,3 +1,3 @@ module Emailable - VERSION = '4.2.1' + VERSION = '4.2.2' end From f2a03c8f0659bcf2f3f662b7b4adc662128e0c29 Mon Sep 17 00:00:00 2001 From: Daniel Arnold Date: Wed, 4 Jun 2025 14:06:47 -0400 Subject: [PATCH 2/3] rename params dup variable to params_copy. add test. remove version bump. --- lib/emailable/client.rb | 12 +++++++----- lib/emailable/version.rb | 2 +- test/authentication_test.rb | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/emailable/client.rb b/lib/emailable/client.rb index db2b78f..992f6c3 100644 --- a/lib/emailable/client.rb +++ b/lib/emailable/client.rb @@ -17,9 +17,9 @@ def initialize end def request(method, endpoint, params = {}) - req_params = params.dup - api_key = req_params.delete(:api_key) - access_token = req_params.delete(:access_token) + params_copy = params.dup + api_key = params_copy.delete(:api_key) + access_token = params_copy.delete(:access_token) uri = URI("#{@base_url}/#{endpoint}") headers = { @@ -31,12 +31,14 @@ def request(method, endpoint, params = {}) tries ||= 3 http_response = if method == :get - uri.query = URI.encode_www_form(req_params) unless req_params.empty? + unless params_copy.empty? + uri.query = URI.encode_www_form(params_copy) + end request = Net::HTTP::Get.new(uri, headers) @connection.request(request) elsif method == :post request = Net::HTTP::Post.new(uri, headers) - request.body = req_params.to_json + request.body = params_copy.to_json @connection.request(request) end diff --git a/lib/emailable/version.rb b/lib/emailable/version.rb index 2a0f9d9..3d51d7d 100644 --- a/lib/emailable/version.rb +++ b/lib/emailable/version.rb @@ -1,3 +1,3 @@ module Emailable - VERSION = '4.2.2' + VERSION = '4.2.1' end diff --git a/test/authentication_test.rb b/test/authentication_test.rb index 1692754..eaa5ef5 100644 --- a/test/authentication_test.rb +++ b/test/authentication_test.rb @@ -30,4 +30,12 @@ def test_request_time_authentication_takes_priority_over_global refute_nil Emailable.verify(@email, api_key: @api_key).domain end + def test_does_not_modify_params + params = { api_key: @api_key, email: @email } + Emailable.verify(params[:email], params) + + assert_equal @api_key, params[:api_key] + assert_equal @email, params[:email] + end + end From 2e64c6e0de8da2ddb6e8688cd213606efd1d6f58 Mon Sep 17 00:00:00 2001 From: Daniel Arnold Date: Wed, 4 Jun 2025 14:12:44 -0400 Subject: [PATCH 3/3] simplify params empty check in query set Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/emailable/client.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/emailable/client.rb b/lib/emailable/client.rb index 992f6c3..29b87d9 100644 --- a/lib/emailable/client.rb +++ b/lib/emailable/client.rb @@ -31,9 +31,7 @@ def request(method, endpoint, params = {}) tries ||= 3 http_response = if method == :get - unless params_copy.empty? - uri.query = URI.encode_www_form(params_copy) - end + uri.query = URI.encode_www_form(params_copy) if params_copy.any? request = Net::HTTP::Get.new(uri, headers) @connection.request(request) elsif method == :post