Skip to content

Commit aab56a9

Browse files
committed
Merge pull request jbox-web#116 from panmari/master
Escaping now search values before wrapping with %.
2 parents 59ddd5c + 6151081 commit aab56a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ajax-datatables-rails/base.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module AjaxDatatablesRails
22
class Base
33
extend Forwardable
4+
include ActiveRecord::Sanitization::ClassMethods
45
class MethodNotImplementedError < StandardError; end
56

67
attr_reader :view, :options, :sortable_columns, :searchable_columns
@@ -126,15 +127,15 @@ def new_search_condition(column, value)
126127
model, column = column.split('.')
127128
model = model.constantize
128129
casted_column = ::Arel::Nodes::NamedFunction.new('CAST', [model.arel_table[column.to_sym].as(typecast)])
129-
casted_column.matches("%#{value}%")
130+
casted_column.matches("%#{sanitize_sql_like(value)}%")
130131
end
131132

132133
def deprecated_search_condition(column, value)
133134
model, column = column.split('.')
134135
model = model.singularize.titleize.gsub( / /, '' ).constantize
135136

136137
casted_column = ::Arel::Nodes::NamedFunction.new('CAST', [model.arel_table[column.to_sym].as(typecast)])
137-
casted_column.matches("%#{value}%")
138+
casted_column.matches("%#{sanitize_sql_like(value)}%")
138139
end
139140

140141
def aggregate_query

0 commit comments

Comments
 (0)