From c91ad4964798e3ddbc42c27a266b0c6ae1957909 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 29 Jun 2020 08:27:07 -0700 Subject: [PATCH] Reject a category with a number of items of 0 Thanks to my nephews for poking holes at the implementation by feeding some stressful input to the game. --- empathy/empathy.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 0593b04..6acf526 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -283,7 +283,7 @@ class CategoryRequest extends React.PureComponent { const match = category.match(/[0-9]+/); if (match) { const num_items = parseInt(match[0], 10); - if (num_items <= MAX_PROMPT_ITEMS) + if (num_items > 0 && num_items <= MAX_PROMPT_ITEMS) category_input.setCustomValidity(""); } } @@ -311,6 +311,12 @@ class CategoryRequest extends React.PureComponent { return; } + if (num_items < 1) { + category_input.setCustomValidity("Category must require at least one item."); + form.reportValidity(); + return; + } + const response = await fetch_post_json("prompts", { items: num_items, prompt: category -- 2.43.0