From 8b452084f3f46925251d20cf22be6d2bef628215 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 13 Sep 2023 10:23:39 +0300 Subject: [PATCH] fix: validation for variant payload number type (#4671) Adds validation to number type for variants --------- Signed-off-by: andreas-unleash --- .../EnvironmentVariantsModal/VariantForm/VariantForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/VariantForm/VariantForm.tsx b/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/VariantForm/VariantForm.tsx index fea165e547..3a61919c17 100644 --- a/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/VariantForm/VariantForm.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/VariantForm/VariantForm.tsx @@ -262,7 +262,10 @@ export const VariantForm = ({ const validatePayload = (payload: IPayload) => { if (!isValidPayload(payload)) { - setError(ErrorField.PAYLOAD, 'Invalid JSON.'); + setError( + ErrorField.PAYLOAD, + payload.type === 'json' ? 'Invalid json' : 'Invalid number' + ); } }; @@ -293,7 +296,7 @@ export const VariantForm = ({ JSON.parse(payload.value); } if (variantTypeNumber && payload.type === 'number') { - Number(payload.value); + return !Number.isNaN(Number(payload.value)); } return true; } catch (e: unknown) {