From 6a61f694eea9f6a8a1ceeb577af76824d419cd66 Mon Sep 17 00:00:00 2001 From: Kane York Date: Wed, 15 Jul 2015 12:23:56 -0700 Subject: [PATCH] Fix float type checks --- .../discourse/components/param-input.js.es6 | 2 +- plugin.rb | 30 +++++++++++++++++-- spec/controllers/queries_controller_spec.rb | 0 .../acceptance/data-explorer-test.js.es6 | 0 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 spec/controllers/queries_controller_spec.rb create mode 100644 test/javascripts/acceptance/data-explorer-test.js.es6 diff --git a/assets/javascripts/discourse/components/param-input.js.es6 b/assets/javascripts/discourse/components/param-input.js.es6 index 9d0a268..0c869dc 100644 --- a/assets/javascripts/discourse/components/param-input.js.es6 +++ b/assets/javascripts/discourse/components/param-input.js.es6 @@ -75,7 +75,7 @@ export default Ember.Component.extend({ case 'boolean': return /^Y|N|#null|true|false/.test(value); case 'double': - return !isNaN(parseFloat(value)); + return !isNaN(parseFloat(value)) || /^(-?)Inf(inity)?$/i.test(value) || /^(-?)NaN$/i.test(value); case 'int_list': return value.split(',').every(function(i) { return /^(-?\d+|null)$/.test(i.trim()); diff --git a/plugin.rb b/plugin.rb index 3e9c36c..5bb6c22 100644 --- a/plugin.rb +++ b/plugin.rb @@ -351,6 +351,12 @@ SQL DataExplorer::Query.from_hash PluginStore.cast_value(psr.type_name, psr.value) end end + + def self.destroy_all + PluginStoreRow.where(plugin_name: DataExplorer.plugin_name) + .where("key LIKE 'q:%'") + .destroy_all + end end class DataExplorer::Parameter @@ -431,9 +437,11 @@ SQL case @type when :int + invalid_format string, 'Not an integer' unless string =~ /^-?\d+$/ value = string.to_i invalid_format string, 'Too large' unless Fixnum === value when :bigint + invalid_format string, 'Not an integer' unless string =~ /^-?\d+$/ value = string.to_i when :boolean value = !!(string =~ /t|true|y|yes|1/i) @@ -458,7 +466,23 @@ SQL invalid_format string, e.message end when :double - value = string.to_f + if string =~ /-?\d*(\.\d+)/ + value = Float(string) + elsif string =~ /^(-?)Inf(inity)?$/i + if $1 + value = -Float::INFINITY + else + value = Float::INFINITY + end + elsif string =~ /^(-?)NaN$/i + if $1 + value = -Float::NAN + else + value = Float::NAN + end + else + invalid_format string + end when :category_id if string =~ /(.*)\/(.*)/ parent_name = $1 @@ -670,7 +694,9 @@ SQL response.sending_file = true end - query_params = MultiJson.load(params[:params]) + params[:params] = params[:_params] if params[:_params] # testing workaround + query_params = {} + query_params = MultiJson.load(params[:params]) if params[:params] opts = {current_user: current_user.username} opts[:explain] = true if params[:explain] == "true" diff --git a/spec/controllers/queries_controller_spec.rb b/spec/controllers/queries_controller_spec.rb new file mode 100644 index 0000000..e69de29 diff --git a/test/javascripts/acceptance/data-explorer-test.js.es6 b/test/javascripts/acceptance/data-explorer-test.js.es6 new file mode 100644 index 0000000..e69de29