From 7dd0a046ae89abad1daa75beead4b7aaff2babb2 Mon Sep 17 00:00:00 2001 From: Jeremy Lingmann Date: Thu, 10 Mar 2011 21:49:38 -0800 Subject: [PATCH] Fixing issue with prepare method. The issue was that [stripped_contents.length..-1] was not capturing the trailing contents as expected. Instead it was grabbing the last 2 characters of my identifier block and then tacking those 2 characters back on to the end. In short, .length and the range operator are not behaving consistently on the input. --- lib/whenever/command_line.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/whenever/command_line.rb b/lib/whenever/command_line.rb index d1bd514..74c8a3a 100644 --- a/lib/whenever/command_line.rb +++ b/lib/whenever/command_line.rb @@ -108,11 +108,15 @@ module Whenever end def prepare(contents) - # Some cron implementations require all non-comment lines to be newline-terminated. - # Preserve any whitespace at the end of contents. (issue #95) - stripped_contents = contents.strip - tail = contents[stripped_contents.length..-1] - stripped_contents.split("\n")[@options[:cut]..-1].join("\n") + tail + # Strip n lines from the top of the file as specified by the :cut option. + # Use split with a -1 limit option to ensure the join is able to rebuild + # the file with all of the original seperators in-tact. + stripped_contents = contents.split($/,-1)[@options[:cut]..-1].join($/) + + # Some cron implementations require all non-comment lines to be newline- + # terminated. (issue #95) Strip all newlines and replace with the default + # platform record seperator ($/) + stripped_contents.gsub!(/\s+$/, $/) end def comment_base