From c4c250adf734340e1ba449c625d7efebe96a902b Mon Sep 17 00:00:00 2001 From: Michael Madison Date: Thu, 11 Apr 2019 03:27:25 -0500 Subject: [PATCH 1/2] sanitize is such an overused method name that it binds to a lot of different things. Because datatables inherit from AjaxDatatablesRails::ActiveRecord which inherits from AjaxDatatablesRails::Base for some odd reason sanitize binds to ActionView's sanitize method which eventually gets to Loofah and Nokogiri which doesn't handle arrays and throws the error I reported in https://github.com/jbox-web/ajax-datatables-rails/issues/325 surprisingly even when you call self.sanitize it does not call the method in the same namespace and file!! because technically the sanitize function that we want is AjaxDatatablesRails::Base's function, to disabiguate we could either rename the function (and because I don't know what else calls it that seemed like a bad idea), or we could help disambiguate by being explicit about which super's method to call. The only way I saw to do this is to call it like this: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data). That may make for unreadable code to some, we could always define another method that then calls AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data). Or if you have another way to fix, have at it. But this breaks in Ruby 2.4.0 and rails 5.2.3 for me without this change. --- lib/ajax-datatables-rails/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index 08bf54bb..e285c593 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: sanitize(data), + data: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data), }.merge(get_additional_data) end From c022c0fde16f8af8ba9f8634af1915c5354f28ad Mon Sep 17 00:00:00 2001 From: Michael Madison Date: Sun, 5 May 2019 02:04:31 -0500 Subject: [PATCH 2/2] shifted to renaming the sanitize function to sanitize_data as discussed --- lib/ajax-datatables-rails/base.rb | 4 ++-- lib/ajax-datatables-rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/base.rb b/lib/ajax-datatables-rails/base.rb index e285c593..f99a5d31 100644 --- a/lib/ajax-datatables-rails/base.rb +++ b/lib/ajax-datatables-rails/base.rb @@ -33,7 +33,7 @@ def as_json(*) { recordsTotal: records_total_count, recordsFiltered: records_filtered_count, - data: AjaxDatatablesRails::Base.instance_method(:sanitize).bind(self).call(data), + data: sanitize_data(data), }.merge(get_additional_data) end @@ -81,7 +81,7 @@ def get_additional_data end end - def sanitize(data) + def sanitize_data(data) data.map do |record| if record.is_a?(Array) record.map { |td| ERB::Util.html_escape(td) } diff --git a/lib/ajax-datatables-rails/version.rb b/lib/ajax-datatables-rails/version.rb index 2e6960f8..7e0ffd6b 100644 --- a/lib/ajax-datatables-rails/version.rb +++ b/lib/ajax-datatables-rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AjaxDatatablesRails - VERSION = '1.0.0' + VERSION = '1.0.1' end