Fixes validation

This commit is contained in:
AliasAlreadyTaken 2024-10-03 12:15:00 +02:00
parent 6655b51a70
commit b0aaebf437

View File

@ -84,6 +84,9 @@ local function validate_responses(t_answers, responses)
if (validate(t_answers, "table", false) == false) then return false end
if (validate(responses, "table", false) == false) then return false end
-- Remove the question
responses["q"] = nil
-- If the responses are not JSON-able, return false
if (minetest.write_json(responses) == nil) then return false end
@ -683,6 +686,10 @@ local function answer_question(id, q_id, playername, responses, overwrite)
record[tostring(q_id)]["responses"] = {}
end
if (t_question["answers"] == nil) then
t_question["answers"] = {}
end
if (validate_responses(t_question["answers"], responses) == false) then
return false, "responses do not fit the questions"
end