From a97ca3852e8c1ccd5dae24bb16607777e9b3de89 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 27 Oct 2026 21:13:54 +0000 Subject: [PATCH] Don't allow negative numbers --- frontend/index.html | 2 ++ frontend/js/load.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/frontend/index.html b/frontend/index.html index 9bf8537..e217d2d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -231,6 +231,8 @@ id="numberof" placeholder="Feladatok mennyisége: " min="1" + max="100" + step="1" /> diff --git a/frontend/js/load.js b/frontend/js/load.js index c51f9af..438bac0 100644 --- a/frontend/js/load.js +++ b/frontend/js/load.js @@ -1,5 +1,10 @@ let questions = null; +const MAX_TOPIC_QUESTIONS = 100; +const QUESTION_COUNT_ERROR = `A feladatok mennyisége 1 és ${MAX_TOPIC_QUESTIONS} közötti egész szám legyen!`; +const isValidQuestionCount = (count) => + Number.isInteger(count) && count >= 1 && count <= MAX_TOPIC_QUESTIONS; + // Auto-detect API base URL const getApiBase = () => { const protocol = window.location.protocol; @@ -57,6 +62,10 @@ const loadQuestions = async ( sourceScheme, questionCount, ) => { + if (!isSearch && !isValidQuestionCount(questionCount)) { + throw new RangeError(QUESTION_COUNT_ERROR); + } + await ensureQuestionsLoaded(); let currentQuestions = questions.slice();