Skip to content

Commit

Permalink
Merge pull request #1251 from presidentbeef/concat_arrays_without_lin…
Browse files Browse the repository at this point in the history
…e_numbers

Avoid nils when concatenating arrays
  • Loading branch information
presidentbeef committed Aug 13, 2018
2 parents 959abc2 + 9d4b517 commit 74a8aea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/brakeman/processors/lib/call_conversion_helper.rb
Expand Up @@ -9,7 +9,8 @@ def all_literals? exp, expected_type = :array
# Join two array literals into one.
def join_arrays lhs, rhs, original_exp = nil
if array? lhs and array? rhs
result = Sexp.new(:array).line(lhs.line)
result = Sexp.new(:array)
result.line(lhs.line || rhs.line)
result.concat lhs[1..-1]
result.concat rhs[1..-1]
result
Expand Down
16 changes: 16 additions & 0 deletions test/tests/alias_processor.rb
Expand Up @@ -155,6 +155,22 @@ def test_array_first
RUBY
end

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

def test_array_plu
assert_alias '[1, 2, 3]', <<-RUBY
x = [1]
y = x + [2, 3]
y
RUBY
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 74a8aea

Please sign in to comment.