Skip to content

Commit

Permalink
Check for sane options in email_notifier
Browse files Browse the repository at this point in the history
Because #set_data_variables will create instance variables for
each key found in options[:data], check to make sure key names are
sane and will not interfer with functioning of EmailNotifier.
  • Loading branch information
Brian Buchalter committed Jul 8, 2013
1 parent 245ce60 commit c7b15dc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/exception_notifier/email_notifier.rb
Expand Up @@ -20,6 +20,7 @@ def self.extended(base)
self.append_view_path "#{File.dirname(__FILE__)}/views"

def exception_notification(env, exception, options={}, default_options={})
check_for_sane_options(options)
load_custom_views

@env = env
Expand All @@ -36,6 +37,7 @@ def exception_notification(env, exception, options={}, default_options={})
end

def background_exception_notification(exception, options={}, default_options={})
check_for_sane_options(options)
load_custom_views

@exception = exception
Expand All @@ -49,6 +51,17 @@ def background_exception_notification(exception, options={}, default_options={})

private

def check_for_sane_options(options)
check_for_sane_data_option(options[:data]) if options[:data].present?
end

def check_for_sane_data_option(data_option)
reserved_keys = %w(env exception options kontroller request backtrace sections data)
data_option.keys.each do |key|
raise "Reserved key '#{key}' used in data option. Please do not use #{reserved_keys.join(",")} as keys." if reserved_keys.include? key.to_s
end
end

def compose_subject
subject = "#{@options[:email_prefix]}"
subject << "#{@kontroller.controller_name}##{@kontroller.action_name}" if @kontroller
Expand Down

0 comments on commit c7b15dc

Please sign in to comment.