From 446c8db35aee5d56d72c465a658bb404c577310c Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Thu, 20 Jul 2023 17:48:08 -0400 Subject: [PATCH] :bug: Add url validation to rules step Signed-off-by: ibolton336 --- .../app/pages/applications/analysis-wizard/schema.ts | 11 +++++------ client/src/app/utils/utils.ts | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/src/app/pages/applications/analysis-wizard/schema.ts b/client/src/app/pages/applications/analysis-wizard/schema.ts index 42a27db38d..8fa8dfc224 100644 --- a/client/src/app/pages/applications/analysis-wizard/schema.ts +++ b/client/src/app/pages/applications/analysis-wizard/schema.ts @@ -11,6 +11,7 @@ import { } from "@app/api/models"; import { useTranslation } from "react-i18next"; import { useAnalyzableApplicationsByMode } from "./utils"; +import { customURLValidation } from "@app/utils/utils"; export const ANALYSIS_MODES = [ "binary", @@ -156,14 +157,12 @@ const useCustomRulesStepSchema = (): yup.SchemaOf => { is: "repository", then: yup.mixed().required(), }), - sourceRepository: yup.mixed().when("rulesKind", { + sourceRepository: yup.string().when("rulesKind", { is: "repository", - then: yup - .string() - .required("This value is required") - .min(3, t("validation.minLength", { length: 3 })) - .max(120, t("validation.maxLength", { length: 120 })), + then: (schema) => + customURLValidation(schema).required("Enter repository url."), }), + branch: yup.mixed().when("rulesKind", { is: "repository", then: yup.mixed(), diff --git a/client/src/app/utils/utils.ts b/client/src/app/utils/utils.ts index 3376d009e6..bee753e836 100644 --- a/client/src/app/utils/utils.ts +++ b/client/src/app/utils/utils.ts @@ -94,10 +94,10 @@ export const getValidatedFromError = (error: unknown | undefined) => { }; export const standardURLRegex = - /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi; + /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/; export const standardStrictURLRegex = - /https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/gi; + /https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/; export const customURLValidation = (schema: StringSchema) => { const gitUrlRegex =