Skip to content

Commit

Permalink
🐛 Add url validation to rules step
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Jul 20, 2023
1 parent a8c9b2c commit 446c8db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions client/src/app/pages/applications/analysis-wizard/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -156,14 +157,12 @@ const useCustomRulesStepSchema = (): yup.SchemaOf<CustomRulesStepValues> => {
is: "repository",
then: yup.mixed<string>().required(),
}),
sourceRepository: yup.mixed<string>().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."),

Check warning on line 163 in client/src/app/pages/applications/analysis-wizard/schema.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/schema.ts#L163

Added line #L163 was not covered by tests
}),

branch: yup.mixed<string>().when("rulesKind", {
is: "repository",
then: yup.mixed<string>(),
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 446c8db

Please sign in to comment.