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:
Gary Pendergast
2025-10-15 14:31:12 +11:00
committed by GitHub
parent 66179c60cd
commit e0cb29ed4c
2 changed files with 5 additions and 1 deletions
@@ -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])