From f0543e229fe41d0068e02b67f4d0af0576586c0a Mon Sep 17 00:00:00 2001 From: Michael Gibney Date: Tue, 18 Apr 2017 15:54:48 -0400 Subject: [PATCH] support signing empty param values, e.g. 's.q=' As long as an empty value for a param (e.g., s.q) is legal, we should support signing it. Current implementation simply drops params with empty values, which without reporting back to the caller, results in invalid auth headers. This should also be supported because in practice, sometimes having a parameter key present with an empty value can differ semantically from having no value explicitly specified for that parameter. --- lib/summon/transport/headers.rb | 2 +- lib/summon/transport/qstring.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/summon/transport/headers.rb b/lib/summon/transport/headers.rb index e08b3df..0dcf09c 100644 --- a/lib/summon/transport/headers.rb +++ b/lib/summon/transport/headers.rb @@ -43,7 +43,7 @@ def digest end def qstr - to_query_string(@params, false) + to_query_string(@params, false, lambda {|k,v| v.nil? }) end private diff --git a/lib/summon/transport/qstring.rb b/lib/summon/transport/qstring.rb index dfbb413..b21e1f9 100644 --- a/lib/summon/transport/qstring.rb +++ b/lib/summon/transport/qstring.rb @@ -5,8 +5,9 @@ module Summon::Transport module Qstring - def to_query_string(hash, urlencode = true) - hash.reject {|k,v| v.nil? || v == ''}.inject([]) do |qs,pair| + def to_query_string(hash, urlencode = true, + reject = lambda {|k,v| v.nil? || v == ''}) + hash.reject(&reject).inject([]) do |qs,pair| qs.tap do k,v = pair if v.is_a?(Array)