Skip to content

Commit

Permalink
Fix infinite loop problem with the NameErrors in block exposures
Browse files Browse the repository at this point in the history
Calling `NameError#message` causes the `did_you_mean` library to endup
being in an infinite loop(Probabaly raises `SystemStackError` at some
point though).

Related to ruby/did_you_mean#158
  • Loading branch information
meinac committed Aug 25, 2021
1 parent 675d3c0 commit 9fe10e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def exec_with_object(options, &block)
# it handles: https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md#language-changes point 3, Proc
raise Grape::Entity::Deprecated.new e.message, 'in ruby 3.0' if e.is_a?(ArgumentError)

raise e.class, e.message
raise e
end

def exec_with_attribute(attribute, &block)
Expand Down
12 changes: 12 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,18 @@ class Parent < Person
expect(representation).to eq(id: nil, name: nil, user: { id: nil, name: nil, email: nil })
end
end

context 'when NameError happens in a parameterized block_exposure' do
before do
subject.expose :raise_no_method_error do |_|
foo
end
end

it 'does not cause infinite loop' do
expect { subject.represent({}, serializable: true) }.to raise_error(NameError)
end
end
end
end

Expand Down

0 comments on commit 9fe10e8

Please sign in to comment.