From 39d14aff1c91355892206bb869738e8da845d3f7 Mon Sep 17 00:00:00 2001 From: Wolvan Date: Tue, 11 Jan 2022 22:04:10 +0100 Subject: [PATCH] Deduplicate entries Duplicate entries were deduplicated during saving but not checked for when verifying for at least 2 options set. This lead to being able to have polls with only a single vote. Now deduplication is run at the start of the creation function. --- src/backend.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend.ts b/src/backend.ts index dbc30f9..6877626 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -70,8 +70,11 @@ export default async function init(router: Router, polls: Storage): Promise { - if (!Array.isArray(pollData.options) || pollData.options.filter(i => i).length < 2) - return "Options must be an array and have at least 2 entries"; + if (!Array.isArray(pollData.options) || pollData.options + .reduce((prev: string[], curr: string) => prev.concat(prev.includes(curr) ? "" : curr), []) + .filter(i => i).length < 2 + ) + return "Options must be an array and have at least 2 different entries"; if (pollData.options.filter(i => i).length > MAX_POLL_OPTIONS) return "Only " + MAX_POLL_OPTIONS + " options are allowed";