Skip to content

Commit 1c1e17b

Browse files
authored
Merge pull request #57 from patterninc/PRED-4997_Patch-Query-Helper
Pred 4997 patch query helper
2 parents f865796 + 17d1ac8 commit 1c1e17b

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
query_helper (0.3.9)
4+
query_helper (0.4.0)
55
activerecord (> 5)
66
activesupport (> 5)
77
sqlite3

lib/query_helper/sql_parser.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def update(sql)
1818

1919
def remove_comments
2020
# Remove SQL inline comments (/* */) and line comments (--)
21-
@sql = @sql.gsub(/\/\*(.*?)\*\//, '').gsub(/--(.*)$/, '')
21+
@sql = @sql.gsub(%r{/\*[^/]*?\*/}m, '') # Removes multi-line comments (/* ... */)
22+
.gsub(/--[^\n]*/, '') # Removes single-line comments (--)
23+
2224
@sql.squish!
2325
end
2426

@@ -186,7 +188,7 @@ def find_aliases
186188
ColumnMap.new(
187189
alias_name: sql_alias,
188190
sql_expression: sql_expression.squish,
189-
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)
191+
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)
190192
) if sql_alias
191193
end
192194
column_maps.compact

lib/query_helper/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class QueryHelper
2-
VERSION = "0.3.9"
2+
VERSION = "0.4.0"
33
end

spec/fixtures/controllers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
class ApplicationController < ActionController::API
55
include Rails.application.routes.url_helpers
66
include QueryHelper::QueryHelperConcern
7+
include ActionController::RequestForgeryProtection
78
before_action :create_query_helper
9+
protect_from_forgery with: :exception
810
end
911

1012
class ParentsController < ApplicationController

0 commit comments

Comments
 (0)