Skip to content

Commit

Permalink
security warning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahujaak committed Nov 4, 2024
1 parent f865796 commit ef2d9b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/query_helper/sql_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def update(sql)

def remove_comments
# Remove SQL inline comments (/* */) and line comments (--)
@sql = @sql.gsub(/\/\*(.*?)\*\//, '').gsub(/--(.*)$/, '')
@sql = @sql.gsub(%r{/\*.*?\*/}m, '') # Removes multi-line comments (/* ... */)
.gsub(/--[^\n]*$/, '') # Removes single-line comments (-- ... until end of line)
@sql.squish!
end

Expand Down Expand Up @@ -186,7 +187,7 @@ def find_aliases
ColumnMap.new(
alias_name: sql_alias,
sql_expression: sql_expression.squish,
aggregate: /(array_agg|avg|bit_and|bit_or|bool_and|bool_or|boolor_agg|booland_agg|count|every|json_agg|jsonb_agg|json_object_agg|jsonb_object_agg|max|min|string_agg|sum|xmlagg)\((.*)\)/.match?(sql_expression)
aggregate: /\b(array_agg|avg|bit_and|bit_or|bool_and|bool_or|boolor_agg|booland_agg|count|every|json_agg|jsonb_agg|json_object_agg|jsonb_object_agg|max|min|string_agg|sum|xmlagg)\((.*?)\)/.match?(sql_expression)
) if sql_alias
end
column_maps.compact
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::API
include Rails.application.routes.url_helpers
include QueryHelper::QueryHelperConcern
before_action :create_query_helper
protect_from_forgery with: :exception
end

class ParentsController < ApplicationController
Expand Down

0 comments on commit ef2d9b7

Please sign in to comment.