mirror of
https://github.com/discourse/discourse-data-explorer.git
synced 2025-07-08 15:22:45 +00:00
Fix float type checks
This commit is contained in:
parent
45c2636ea0
commit
6a61f694ee
@ -75,7 +75,7 @@ export default Ember.Component.extend({
|
|||||||
case 'boolean':
|
case 'boolean':
|
||||||
return /^Y|N|#null|true|false/.test(value);
|
return /^Y|N|#null|true|false/.test(value);
|
||||||
case 'double':
|
case 'double':
|
||||||
return !isNaN(parseFloat(value));
|
return !isNaN(parseFloat(value)) || /^(-?)Inf(inity)?$/i.test(value) || /^(-?)NaN$/i.test(value);
|
||||||
case 'int_list':
|
case 'int_list':
|
||||||
return value.split(',').every(function(i) {
|
return value.split(',').every(function(i) {
|
||||||
return /^(-?\d+|null)$/.test(i.trim());
|
return /^(-?\d+|null)$/.test(i.trim());
|
||||||
|
30
plugin.rb
30
plugin.rb
@ -351,6 +351,12 @@ SQL
|
|||||||
DataExplorer::Query.from_hash PluginStore.cast_value(psr.type_name, psr.value)
|
DataExplorer::Query.from_hash PluginStore.cast_value(psr.type_name, psr.value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.destroy_all
|
||||||
|
PluginStoreRow.where(plugin_name: DataExplorer.plugin_name)
|
||||||
|
.where("key LIKE 'q:%'")
|
||||||
|
.destroy_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DataExplorer::Parameter
|
class DataExplorer::Parameter
|
||||||
@ -431,9 +437,11 @@ SQL
|
|||||||
|
|
||||||
case @type
|
case @type
|
||||||
when :int
|
when :int
|
||||||
|
invalid_format string, 'Not an integer' unless string =~ /^-?\d+$/
|
||||||
value = string.to_i
|
value = string.to_i
|
||||||
invalid_format string, 'Too large' unless Fixnum === value
|
invalid_format string, 'Too large' unless Fixnum === value
|
||||||
when :bigint
|
when :bigint
|
||||||
|
invalid_format string, 'Not an integer' unless string =~ /^-?\d+$/
|
||||||
value = string.to_i
|
value = string.to_i
|
||||||
when :boolean
|
when :boolean
|
||||||
value = !!(string =~ /t|true|y|yes|1/i)
|
value = !!(string =~ /t|true|y|yes|1/i)
|
||||||
@ -458,7 +466,23 @@ SQL
|
|||||||
invalid_format string, e.message
|
invalid_format string, e.message
|
||||||
end
|
end
|
||||||
when :double
|
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
|
when :category_id
|
||||||
if string =~ /(.*)\/(.*)/
|
if string =~ /(.*)\/(.*)/
|
||||||
parent_name = $1
|
parent_name = $1
|
||||||
@ -670,7 +694,9 @@ SQL
|
|||||||
response.sending_file = true
|
response.sending_file = true
|
||||||
end
|
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 = {current_user: current_user.username}
|
||||||
opts[:explain] = true if params[:explain] == "true"
|
opts[:explain] = true if params[:explain] == "true"
|
||||||
|
0
spec/controllers/queries_controller_spec.rb
Normal file
0
spec/controllers/queries_controller_spec.rb
Normal file
Loading…
x
Reference in New Issue
Block a user