From a6b1822ca7a5d86d99b964ae5e4fb40d87b93300 Mon Sep 17 00:00:00 2001 From: Aaron Windsor Date: Thu, 14 May 2015 17:35:06 -0400 Subject: [PATCH] Allow equals signs in values that are set on the fly The current code strips everything after the first equals sign in the value of a variable set on the fly. For example, `whenever --set 'a=b=c&d=e'` will set a to 'b' and d to 'e'. I noticed this when trying to pass a base64-encoded value that had trailing equals signs which were all stripped off. This patch fixes this stripping by interpreting everything after the first equals sign in a key-value pair as the value. --- lib/whenever/job_list.rb | 2 +- test/functional/command_line_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/whenever/job_list.rb b/lib/whenever/job_list.rb index be208048..45d83d18 100644 --- a/lib/whenever/job_list.rb +++ b/lib/whenever/job_list.rb @@ -89,7 +89,7 @@ def pre_set(variable_string = nil) pairs = variable_string.split('&') pairs.each do |pair| next unless pair.index('=') - variable, value = *pair.split('=') + variable, value = *pair.split('=', 2) unless variable.nil? || variable == "" || value.nil? || value == "" variable = variable.strip.to_sym set(variable, value.strip) diff --git a/test/functional/command_line_test.rb b/test/functional/command_line_test.rb index 228d4e0d..3e42b13d 100644 --- a/test/functional/command_line_test.rb +++ b/test/functional/command_line_test.rb @@ -329,3 +329,19 @@ class PreparingOutputTest < Whenever::TestCase assert_equal existing, @command.send(:prepare, existing) end end + +class PreservingEqualsInSetValuesTest < Whenever::TestCase + setup do + @output = Whenever.cron :set => 'password=ABC=123&user=admin', :string => \ + <<-file + job_type :my_job, 'USER=:user PASSWORD=:password' + every 2.hours do + my_job 'foobar' + end + file + end + + should "preserve any equals signs that occur in set values" do + assert_match "USER=admin PASSWORD=ABC=123", @output + end +end