labml icon indicating copy to clipboard operation
labml copied to clipboard

HEREDOC parse error & warning on SQL string with no substitution

Open RichardGrossman opened this issue 9 years ago • 4 comments

ERROR IS:

product_ingredients_controller.rb:8 :: parse error on value "<<" (tLSHFT)	
Could not parse product_ingredients_controller.rb

CODE (notice the squiggly heredoc: <<~ not <<-

def recipeslist
    query =<<~SQL.gsub(/[\s\t]*\n/, ' ').strip
      select
      i.*,
      pi.*,
      p.*,
      p.id as "product_id",
      p.brand_id,
      b.name as "brandname"
      from product_ingredients pi
      join ingredients i on pi.ingredient_id = i.id
      join products p on pi.product_id = p.id
      join brands b on b.id = p.brand_id
      where pi.client_id = #{@_user_client_id}
      and i.client_id = #{@_user_client_id}
      and p.client_id = #{@_user_client_id}
      order by
      b.name,
      p.description,
      pi.product_id,
      i.name
    SQL
   
    @report = Ingredient.find_by_sql(query)

RichardGrossman avatar May 27 '17 19:05 RichardGrossman

As I mentioned in #1025, <<~ is not supported yet. It's not possible that Brakeman is generating a warning about this code. It can't be warning about code in a file that can't be parsed.

It would be helpful to see the SQL injection warning. I would suggest using the -f plain or -f html reports so the file name is reported.

presidentbeef avatar May 28 '17 21:05 presidentbeef

http://www.zenspider.com/releases/2017/07/ruby_parser-version-3-10-0-has-been-released.html

Time to bump ruby_parser to pick up squiggly heredocs support :)

reedloden avatar Jul 18 '17 17:07 reedloden

The 3.7.0 release of Brakeman included those changes already if you are using the brakeman gem.

presidentbeef avatar Jul 18 '17 17:07 presidentbeef

Still not sure where the "warning on SQL string with no substitution" part comes from or what you mean by it. There is substitution (@_user_client_id) and Brakeman probably should warn on it.

presidentbeef avatar Aug 13 '17 21:08 presidentbeef