Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 749c829

Browse files
author
Sam Phippen
committed
Prevent MultipleExceptionError#add from allowing self ot be added to the list of all_exceptions
This was exposed by #2112 which contains a spec which uses `describe_successfully` which seems to somehow add the existing `MultipleExceptionError` to itself when it fails. This **does not happen** if the example passes (presumably because an error is not generated). When we format the exception [here](https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/exception_presenter.rb#L330) we use FlatMap, which is going to continuously unpack the exception, causing infinite recursion. This patch prevents `MultipleExceptionError::InterfaceTag#add` from allowing `self` to be included in the `all_exceptions` array. This fixes the problem. As far as I can tell from running our suite, the `self` being added case never actually happens during normal RSpec execution and so adding this is fine. I added a spec which demonstrates this behaviour in case that turns out to be problematic in the future. I can't imagine that happening though as this will precisely cause the same infinite recursion bug.
1 parent a9f8475 commit 749c829

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ def add(exception)
408408
# ignore it.
409409
return if Pending::PendingExampleFixedError === exception
410410

411+
return if exception == self
412+
411413
all_exceptions << exception
412414

413415
if exception.class.name =~ /RSpec/

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,12 @@ def new_multiple_exception_error
695695
end
696696
end
697697

698+
it "does not let you add itself to the list of all_exceptions" do
699+
m =MultipleExceptionError.new
700+
m.add(m)
701+
expect(m.all_exceptions).to_not include(m)
702+
end
703+
698704
it 'supports the same interface as `RSpec::Expectations::MultipleExpectationsNotMetError`' do
699705
skip "Skipping to allow an rspec-expectations PR to add a new method and remain green" if ENV['NEW_MUTLI_EXCEPTION_METHOD']
700706

0 commit comments

Comments
 (0)