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