On 06/06/11 - 02:44:15PM, Francesco Vollero wrote:
> This patch is to fix a problem with Base64.b64encode for credentials in RHEVM 
> driver, due to a wrong way in pack to add \n every 60 chars i had to use this 
> hack.
> The issue is not present in Ruby 1.9.x in fact they use a method called 
> strict_encode64() that is the same as my hack.
> 
> 
> Signed-off-by: Francesco Vollero <[email protected]>
> ---
>  .../lib/deltacloud/drivers/rhevm/rhevm_client.rb   |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb 
> b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> index 5d28b3d..80f5a91 100644
> --- a/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> +++ b/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
> @@ -150,7 +150,9 @@ module RHEVM
>      end
> 
>      def auth_header
> -      { :authorization => "Basic " + 
> Base64.encode64("#{@credentials[:username]}:#{@credentials[:password]}"), }
> +      # As RDOC says this is the function for strict_encode64:
> +      encoded_credentials = 
> ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
> +      { :authorization => "Basic " + encoded_credentials }
>      end

ACK to the code, it looks fine.  I would suggest adding a better comment to the
code, though, so the next person reading the code isn't confused.  Something
like:

# in ruby 1.8, the Base64.encode64 method automatically adds \n after every
# 60 characters.  Strip that out here.  Ruby 1.9 has Base64.strict_encode64()
# which does not have this problem.

-- 
Chris Lalancette

Reply via email to