lib/brakeman/processors/alias_processor.rb
def process_array_join array, join_str
    # Empty array
    if array.length == 1
      return s(:str, '').line(array.line)
    end

    result = s().line(array.line)

    join_value = if string? join_str
                   join_str.value
                 else
                   nil
                 end

    if array.length > 2
      array[1..-2].each do |e|
        result << join_item(e, join_value)
      end
    end

    result << join_item(array.last, nil)

    # Combine the strings at the beginning because that's what RubyParser does
    combined_first = ""
    result.each do |e|
      if string? e
        combined_first << e.value
      elsif e.is_a? String
        combined_first << e
      else
        break
      end
    end

    # Remove the strings at the beginning
    result.reject! do |e|
      if e.is_a? String or string? e
        true
      else
        break
      end
    end

    result.unshift combined_first

    # Have to fix up strings that follow interpolation
    string = result.reduce(s(:dstr).line(array.line)) do |memo, e|
      if string? e and node_type? memo.last, :evstr
        e.value = "#{join_value}#{e.value}"
      elsif join_value and node_type? memo.last, :evstr and node_type? e, :evstr
        memo << s(:str, join_value).line(e.line)
      end

      memo << e
    end

    # Convert (:dstr, "hello world")
    # to (:str, "hello world")
    if string.length == 2 and string.last.is_a? String
      string[0] = :str
    end

    string
  end
# Painful conversion of Array#join into string interpolation
Painful conversion of Array#join into string interpolation
Painful conversion of Array#join into string interpolation
def process_array_join array, join_str
    if array.length == 1
      return s(:str, '').line(array.line)
    end
    result = s().line(array.line)
    join_value = if string? join_str
                   join_str.value
                 else
                   nil
                 end
    if array.length > 2
      array[1..-2].each do |e|
        result << join_item(e, join_value)
      end
    end
    result << join_item(array.last, nil)
    combined_first = ""
    result.each do |e|
      if string? e
        combined_first << e.value
      elsif e.is_a? String
        combined_first << e
      else
        break
      end
    end
    result.reject! do |e|
      if e.is_a? String or string? e
        true
      else
        break
      end
    end
    result.unshift combined_first
    string = result.reduce(s(:dstr).line(array.line)) do |memo, e|
      if string? e and node_type? memo.last, :evstr
        e.value = "#{join_value}#{e.value}"
      elsif join_value and node_type? memo.last, :evstr and node_type? e, :evstr
        memo << s(:str, join_value).line(e.line)
      end
      memo << e
    end
    if string.length == 2 and string.last.is_a? String
      string[0] = :str
    end
    string
  end
def process_array_join array , join_str if array . length == 1 return s ( :str , '' ) . line ( array . line ) end result = s ( ) . line ( array . line ) join_value = if string? join_str join_str . value else nil end if array . length > 2 array [ 1 .. - 2 ] . each do | e | result << join_item ( e , join_value ) end end result << join_item ( array . last , nil ) combined_first = "" result . each do | e | if string? e combined_first << e . value elsif e . is_a? String combined_first << e else break end end result . reject! do | e | if e . is_a? String or string? e true else break end end result . unshift combined_first string = result . reduce ( s ( :dstr ) . line ( array . line ) ) do | memo , e | if string? e and node_type? memo . last , :evstr e . value = "#{join_value}#{e.value}" elsif join_value and node_type? memo . last , :evstr and node_type? e , :evstr memo << s ( :str , join_value ) . line ( e . line ) end memo << e end if string . length == 2 and string . last . is_a? String string [ 0 ] = :str end string end
Painful conversion of Array#join into string interpolation
Painful conversion of Array#join into string interpolation
# Empty array # Combine the strings at the beginning because that's what RubyParser does # Remove the strings at the beginning # Have to fix up strings that follow interpolation # Convert (:dstr, "hello world") # to (:str, "hello world")
array
join_str