mirror of
https://github.com/discourse/discourse.git
synced 2026-07-31 16:48:26 -05:00
DEV: Improve validity checking of JSON param values. (#35401)
The validity checking for parameter values being passed in expects them all to be strings, then casts them to their appropriate type after confirming that they're valid. Rather than bypassing these checks, it's safer to convert the values to strings, then continue with the existing validity checks.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user