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.rbindex 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 DiscourseDataExplorerdef 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_sif string.blank?if @nullablediff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rbindex 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 dofoo: 42,bar: "test",},- }+ },+ as: :jsonexpect(response.status).to eq(200)expect(response_json["success"]).to eq(true)expect(response_json["columns"]).to eq(%w[my_value text_value])