Skip to content

Commit

Permalink
Convert s(:lambda) to s(:call) in Sexp#block_call
Browse files Browse the repository at this point in the history
Fixes #1410
  • Loading branch information
presidentbeef committed Oct 21, 2019
1 parent 428bad2 commit 40ff340
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/ruby_parser/bm_sexp.rb
Expand Up @@ -371,7 +371,12 @@ def else_clause
# s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
def block_call
expect :iter
self[1]

if self[1].node_type == :lambda
s(:call, nil, :lambda).line(self.line)
else
self[1]
end
end

#Returns block of a call with a block.
Expand Down
5 changes: 4 additions & 1 deletion test/apps/rails6/config/routes.rb
@@ -1,4 +1,7 @@
Rails.application.routes.draw do
resources :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

# https://github.com/presidentbeef/brakeman/issues/1410
x = ->(args) {
}
end
6 changes: 1 addition & 5 deletions test/tests/sexp.rb
Expand Up @@ -101,11 +101,7 @@ def test_method_call_with_block
def test_stabby_lambda_no_args
exp = parse "->{ hi }"

if RubyParser::Parser::VERSION.split(".").map(&:to_i).zip([3,14,0]).all? { |a, b| a >= b }
assert_equal s(:lambda), exp.block_call
else
assert_equal s(:call, nil, :lambda), exp.block_call
end
assert_equal s(:call, nil, :lambda), exp.block_call
assert_equal s(:args), exp.block_args
assert_equal s(:call, nil, :hi), exp.block
end
Expand Down

0 comments on commit 40ff340

Please sign in to comment.