Skip to content

A platform for community discussion. Free, open, simple.

DEV: Improve validity checking of JSON param values. (#35401)

Gary Pendergaste0cb29ed4cfc
diff --git a/plugins/discourse-data-explorer/lib/discourse_data_explorer/parameter.rb b/plugins/discourse-data-explorer/lib/discourse_data_explorer/parameter.rb
index f8b3d77b1d3..71755f3f96c 100644
--- a/plugins/discourse-data-explorer/lib/discourse_data_explorer/parameter.rb
+++ b/plugins/discourse-data-explorer/lib/discourse_data_explorer/parameter.rb
@@ -110,6 +110,9 @@ module DiscourseDataExplorer
def cast_to_ruby(string)
string = @default unless string
+ # Since we allow passing a JSON object for the params, the most straightforward way to
+ # check that the value is valid is to convert it back to a string.
+ string = string.to_s
if string.blank?
if @nullable
diff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
index 76f5ea517ff..f011e929d52 100644
--- a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
+++ b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
@@ -199,7 +199,8 @@ describe DiscourseDataExplorer::QueryController do
foo: 42,
bar: "test",
},
- }
+ },
+ as: :json
expect(response.status).to eq(200)
expect(response_json["success"]).to eq(true)
expect(response_json["columns"]).to eq(%w[my_value text_value])