Skip to content

Commit

Permalink
Always set line number for joined arrays
Browse files Browse the repository at this point in the history
Fixes #1499
  • Loading branch information
presidentbeef committed Aug 17, 2020
1 parent aaa1bf3 commit 649b7f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/brakeman/processors/lib/call_conversion_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def all_literals? exp, expected_type = :array
def join_arrays lhs, rhs, original_exp = nil
if array? lhs and array? rhs
result = Sexp.new(:array)
result.line(lhs.line || rhs.line)
result.line(lhs.line || rhs.line || 1)
result.concat lhs[1..-1]
result.concat rhs[1..-1]
result
Expand Down
13 changes: 12 additions & 1 deletion test/tests/alias_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,25 @@ def test_array_plus_equals
RUBY
end

def test_array_plu
def test_array_plus
assert_alias '[1, 2, 3]', <<-RUBY
x = [1]
y = x + [2, 3]
y
RUBY
end

def test_array_plus_no_lines
a1 = s(:array, s(:lit, 1))
a2 = s(:array, s(:lit, 2))
joined = Brakeman::AliasProcessor.new.join_arrays(a1, a2)
expected = s(:array,
s(:lit, 1),
s(:lit, 2))

assert_equal expected, joined
end

def test_hash_index
assert_alias "'You say goodbye, I say :hello'", <<-RUBY
x = {:goodbye => "goodbye cruel world" }
Expand Down

0 comments on commit 649b7f3

Please sign in to comment.