Skip to content

Commit

Permalink
Do a shallow copy of params hash in Notifier#build_notice (airbrake#234)
Browse files Browse the repository at this point in the history
At various points in the filter call chains of building up an Airbrake
notice, the code mutates the params hash that is passed in (adding
keys like :priority and safe_level). A simple dup means the calling
code no longer has to worry about that params hash mutating.
  • Loading branch information
Jason Yanowitz authored and kyrylo committed Jun 21, 2017
1 parent c86ac39 commit fc43a18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/airbrake-ruby/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def build_notice(exception, params = {})
exception[:params].merge!(params)
exception
else
Notice.new(@config, convert_to_exception(exception), params)
Notice.new(@config, convert_to_exception(exception), params.dup)
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,13 @@ def to_json(*)
end

context "given a non-exception with calculated internal frames only" do
it "prevents mutation of passed-in params hash" do
params = { only_this_item: true }
notice = @airbrake.build_notice(RuntimeError.new('bingo'), params)
notice[:params][:extra_item] = :not_in_original_params
expect(params).to eq(only_this_item: true)
end

it "returns the internal frames nevertheless" do
backtrace = [
"/airbrake-ruby/lib/airbrake-ruby/notifier.rb:84:in `build_notice'",
Expand Down

0 comments on commit fc43a18

Please sign in to comment.