From 7efb185caf1b5a3a13e7086c44110a7eb95fbeb7 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 10 Mar 2020 10:10:01 +0200 Subject: [PATCH] RRule: sanitize byday/month before using. It was crashing when they were not array, so this change makes sure they are. Additionally, since we don't support the number prefixes for by day (e.g. 3SA) at least sanitize the ones we can handle which are the ones prefixed by 1 such as 1SA, and turn them into the equivalent SA. --- src/widgets/RRule.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/widgets/RRule.tsx b/src/widgets/RRule.tsx index c56e8b8..0c0374d 100644 --- a/src/widgets/RRule.tsx +++ b/src/widgets/RRule.tsx @@ -83,6 +83,30 @@ const menuItemsWeekDays = weekdays.map((day) => { ); }); +function makeArray(item: T) { + if (item === undefined) { + return item; + } else if (Array.isArray(item)) { + return item; + } else { + return [item]; + } +} + +function sanitizeByDay(item: string | string[] | undefined) { + const ret = makeArray(item); + if (Array.isArray(ret)) { + return (ret as string[]).map((value) => { + if (parseInt(value) === 1) { + return value.substr(1); + } + return value; + }); + } else { + return ret; + } +} + const styles = { multiSelect: { minWidth: 120, maxWidth: '100%' }, width: { width: 120 }, @@ -152,7 +176,7 @@ export default function RRule(props: PropsType) { Weekdays ) => { const value = event.target.value as string[];