Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Text,
theme,
Tooltip,
truncate,
} from "@webstudio-is/design-system";
import { ArrowRightIcon, TrashIcon } from "@webstudio-is/icons";
import {
Expand Down
30 changes: 24 additions & 6 deletions packages/sdk/src/schema/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,34 @@ const DefaultPagePage = z
"/build prefix is reserved for the system"
);

export const OldPagePath = z
.string()
.refine((path) => path !== "", "Can't be empty")
.refine((path) => path !== "/", "Can't be just a /")
.refine(
(path) => path === "" || path.startsWith("/"),
"Must start with a / or a full URL e.g. https://website.org"
)
.refine((path) => path.endsWith("/") === false, "Can't end with a /")
.refine((path) => path.includes("//") === false, "Can't contain repeating /")
.refine(
(path) => /^[-_a-zA-Z0-9*:?\\/.]*$/.test(path), // Allow uppercase letters (A-Z)
"Only a-z, A-Z, 0-9, -, _, /, :, ?, . and * are allowed"
)
.refine(
(path) => path !== "/s" && path.startsWith("/s/") === false,
"/s prefix is reserved for the system"
)
.refine(
(path) => path !== "/build" && path.startsWith("/build/") === false,
"/build prefix is reserved for the system"
);

export const PagePath = DefaultPagePage.refine(
(path) => path === "" || path.startsWith("/"),
"Must start with a / or a full URL e.g. https://website.org"
);

// added this for old path input under redirect section of page settings
export const OldPagePath = DefaultPagePage.refine(
(path) => path === "" || path.startsWith("/"),
"Must start with a / and it must be full path e.g. /project/id"
);

const Page = z.object({
...commonPageFields,
Expand Down Expand Up @@ -152,7 +170,7 @@ export const ProjectNewRedirectPath = PagePath.or(
);

export const PageRedirect = z.object({
old: PagePath,
old: OldPagePath,
new: ProjectNewRedirectPath,
status: z.enum(["301", "302"]).optional(),
});
Expand Down
Loading