diff --git a/backend/src/server/routes/v1/project-env-router.ts b/backend/src/server/routes/v1/project-env-router.ts index b93ffe928..b2f7ffc2c 100644 --- a/backend/src/server/routes/v1/project-env-router.ts +++ b/backend/src/server/routes/v1/project-env-router.ts @@ -22,7 +22,10 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => { }), body: z.object({ name: z.string().trim(), - slug: z.string().trim() + slug: z + .string() + .regex(/^[^./]*$/g) + .trim() }), response: { 200: z.object({ @@ -77,7 +80,11 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => { id: z.string().trim() }), body: z.object({ - slug: z.string().trim().optional(), + slug: z + .string() + .regex(/^[^./]*$/g) + .trim() + .optional(), name: z.string().trim().optional(), position: z.number().optional() }), diff --git a/frontend/src/components/basic/dialog/AddUpdateEnvironmentDialog.tsx b/frontend/src/components/basic/dialog/AddUpdateEnvironmentDialog.tsx index de5337ae6..e55fc5843 100644 --- a/frontend/src/components/basic/dialog/AddUpdateEnvironmentDialog.tsx +++ b/frontend/src/components/basic/dialog/AddUpdateEnvironmentDialog.tsx @@ -17,6 +17,7 @@ type Props = { }; // TODO: Migrate to better form management and validation. Preferable react-hook-form + yup +// We should remove this? /** * The dialog modal for when the user wants to create a new workspace * @param {*} param0 diff --git a/frontend/src/components/v2/SecretInput/SecretInput.tsx b/frontend/src/components/v2/SecretInput/SecretInput.tsx index deb33ec81..d6a580ee3 100644 --- a/frontend/src/components/v2/SecretInput/SecretInput.tsx +++ b/frontend/src/components/v2/SecretInput/SecretInput.tsx @@ -115,7 +115,6 @@ export const SecretInput = forwardRef( }); useEffect(() => { - let currentEnvironment = propEnvironment; let currentSecretPath = propSecretPath || "/"; @@ -134,7 +133,13 @@ export const SecretInput = forwardRef( currentSecretPath = `/${folderPaths?.join("/")}` || "/"; } - if (!currentEnvironment || !decryptFileKey || !currentSecretPath || !currentWorkspace || !referenceKey) { + if ( + !currentEnvironment || + !decryptFileKey || + !currentSecretPath || + !currentWorkspace || + !referenceKey + ) { // this need to clean up? setListReference(currentListReference); return; @@ -142,8 +147,7 @@ export const SecretInput = forwardRef( setSecretPath(currentSecretPath); setEnvironment(currentEnvironment); setShowReferencePopup(true); - - }, [referenceKey]) + }, [referenceKey]); useEffect(() => { const currentListReference: ReferenceType[] = []; @@ -195,7 +199,6 @@ export const SecretInput = forwardRef( setLastSelectionIndex(pos); setReferenceKey(match?.[2]); } - setShowReferencePopup(!!match); } @@ -224,11 +227,10 @@ export const SecretInput = forwardRef( setValue(newValue); // TODO: there should be a better way to do onChange?.({ target: { value: newValue } } as any); + setCaretPos(currCaretPos); if (event.currentTarget) { - setCaretPos(currCaretPos); setTimeout(() => { - // on next tick referencePopup(newValue, currCaretPos); }, 200); @@ -277,25 +279,28 @@ export const SecretInput = forwardRef( ]; let oldReferenceStr = oldReference.slice(2, -1); + let currentPath = type === "environment" ? slug! : name; + currentPath = currentPath.replace(/\./g, "\\."); let replaceReference = ""; let offset = 3; switch (type) { case "folder": - replaceReference = `${oldReferenceStr}${name}.`; + replaceReference = `${oldReferenceStr}${currentPath}.`; offset -= 1; break; case "secret": { if (oldReferenceStr.indexOf(".") === -1) oldReferenceStr = ""; - replaceReference = `${oldReferenceStr}${name}`; + replaceReference = `${oldReferenceStr}${currentPath}`; break; } case "environment": - replaceReference = `${slug}.`; + replaceReference = `${currentPath}.`; offset -= 1; break; default: } + replaceReference = replaceReference.replace(/[//]/g, ""); newValue = `${start}$\{${replaceReference}}${end}`; setValue(newValue); // TODO: there should be a better way to do diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx index 477816670..2525d57ef 100644 --- a/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx +++ b/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/AddEnvironmentModal.tsx @@ -16,7 +16,7 @@ type Props = { const schema = yup.object({ environmentName: yup.string().label("Environment Name").required(), - environmentSlug: yup.string().label("Environment Slug").required() + environmentSlug: yup.string().label("Environment Slug").matches(/^[^./]*$/g, { message: "Invalid [.] or [/] not allowed"}).required() }); export type FormData = yup.InferType; diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/UpdateEnvironmentModal.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/UpdateEnvironmentModal.tsx index ecd91303d..16b0b71c6 100644 --- a/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/UpdateEnvironmentModal.tsx +++ b/frontend/src/views/Settings/ProjectSettingsPage/components/EnvironmentSection/UpdateEnvironmentModal.tsx @@ -16,7 +16,7 @@ type Props = { const schema = yup.object({ name: yup.string().label("Environment Name").required(), - slug: yup.string().label("Environment Slug").required() + slug: yup.string().label("Environment Slug").matches(/^[^./]*$/g, { message: "Invalid [.] or [/] not allowed"}).required() }); export type FormData = yup.InferType;