From f49a02449c4928aef56cecbf908cf585ea0d4fca Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 17 Mar 2021 20:12:00 -0400 Subject: [PATCH] fix(ui): add validation to hostname/IP fields (#1206) --- .../Notifications/NotificationsEmail.tsx | 10 +++++++--- src/components/Settings/RadarrModal/index.tsx | 17 +++++++++++++---- src/components/Settings/SettingsPlex.tsx | 10 +++++++--- src/components/Settings/SonarrModal/index.tsx | 17 +++++++++++++---- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/components/Settings/Notifications/NotificationsEmail.tsx b/src/components/Settings/Notifications/NotificationsEmail.tsx index 4419ac8b9..7da5c79e6 100644 --- a/src/components/Settings/Notifications/NotificationsEmail.tsx +++ b/src/components/Settings/Notifications/NotificationsEmail.tsx @@ -73,9 +73,13 @@ const NotificationsEmail: React.FC = () => { emailFrom: Yup.string() .required(intl.formatMessage(messages.validationEmail)) .email(intl.formatMessage(messages.validationEmail)), - smtpHost: Yup.string().required( - intl.formatMessage(messages.validationSmtpHostRequired) - ), + smtpHost: Yup.string() + .required(intl.formatMessage(messages.validationSmtpHostRequired)) + .matches( + // eslint-disable-next-line + /^(([a-z]|\d|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*)?([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])$/i, + intl.formatMessage(messages.validationSmtpHostRequired) + ), smtpPort: Yup.number().required( intl.formatMessage(messages.validationSmtpPortRequired) ), diff --git a/src/components/Settings/RadarrModal/index.tsx b/src/components/Settings/RadarrModal/index.tsx index ef27a6573..7bc0e1610 100644 --- a/src/components/Settings/RadarrModal/index.tsx +++ b/src/components/Settings/RadarrModal/index.tsx @@ -91,9 +91,13 @@ const RadarrModal: React.FC = ({ name: Yup.string().required( intl.formatMessage(messages.validationNameRequired) ), - hostname: Yup.string().required( - intl.formatMessage(messages.validationHostnameRequired) - ), + hostname: Yup.string() + .required(intl.formatMessage(messages.validationHostnameRequired)) + .matches( + // eslint-disable-next-line + /^(([a-z]|\d|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*)?([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])$/i, + intl.formatMessage(messages.validationHostnameRequired) + ), port: Yup.number().required( intl.formatMessage(messages.validationPortRequired) ), @@ -312,7 +316,12 @@ const RadarrModal: React.FC = ({ } }} secondaryDisabled={ - !values.apiKey || !values.hostname || !values.port || isTesting + !values.apiKey || + !values.hostname || + !values.port || + isTesting || + isSubmitting || + !isValid } okDisabled={!isValidated || isSubmitting || isTesting || !isValid} onOk={() => handleSubmit()} diff --git a/src/components/Settings/SettingsPlex.tsx b/src/components/Settings/SettingsPlex.tsx index 7da8fecac..b1bc5fa38 100644 --- a/src/components/Settings/SettingsPlex.tsx +++ b/src/components/Settings/SettingsPlex.tsx @@ -113,9 +113,13 @@ const SettingsPlex: React.FC = ({ onComplete }) => { const intl = useIntl(); const { addToast, removeToast } = useToasts(); const PlexSettingsSchema = Yup.object().shape({ - hostname: Yup.string().required( - intl.formatMessage(messages.validationHostnameRequired) - ), + hostname: Yup.string() + .required(intl.formatMessage(messages.validationHostnameRequired)) + .matches( + // eslint-disable-next-line + /^(([a-z]|\d|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*)?([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])$/i, + intl.formatMessage(messages.validationHostnameRequired) + ), port: Yup.number().required( intl.formatMessage(messages.validationPortRequired) ), diff --git a/src/components/Settings/SonarrModal/index.tsx b/src/components/Settings/SonarrModal/index.tsx index 6d04b453a..a9411f5d5 100644 --- a/src/components/Settings/SonarrModal/index.tsx +++ b/src/components/Settings/SonarrModal/index.tsx @@ -102,9 +102,13 @@ const SonarrModal: React.FC = ({ name: Yup.string().required( intl.formatMessage(messages.validationNameRequired) ), - hostname: Yup.string().required( - intl.formatMessage(messages.validationHostnameRequired) - ), + hostname: Yup.string() + .required(intl.formatMessage(messages.validationHostnameRequired)) + .matches( + // eslint-disable-next-line + /^(([a-z]|\d|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*)?([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])$/i, + intl.formatMessage(messages.validationHostnameRequired) + ), port: Yup.number().required( intl.formatMessage(messages.validationPortRequired) ), @@ -341,7 +345,12 @@ const SonarrModal: React.FC = ({ } }} secondaryDisabled={ - !values.apiKey || !values.hostname || !values.port || isTesting + !values.apiKey || + !values.hostname || + !values.port || + isTesting || + isSubmitting || + !isValid } okDisabled={!isValidated || isSubmitting || isTesting || !isValid} onOk={() => handleSubmit()}