diff --git a/packages/sdk/src/schema/pages.test.ts b/packages/sdk/src/schema/pages.test.ts index 14c86501599e..a0ce119bc27f 100644 --- a/packages/sdk/src/schema/pages.test.ts +++ b/packages/sdk/src/schema/pages.test.ts @@ -1,5 +1,5 @@ import { describe, test, expect } from "vitest"; -import { OldPagePath, ProjectNewRedirectPath } from "./pages"; +import { OldPagePath, PagePath, ProjectNewRedirectPath } from "./pages"; describe("OldPagePath", () => { describe("basic validation", () => { @@ -192,6 +192,26 @@ describe("OldPagePath", () => { }); }); +describe("PagePath", () => { + describe("path length validation", () => { + test("accepts a path of exactly 255 characters", () => { + const path = "/" + "a".repeat(254); + expect(PagePath.safeParse(path).success).toBe(true); + }); + + test("rejects a path exceeding 255 characters", () => { + const path = "/" + "a".repeat(255); + const result = PagePath.safeParse(path); + expect(result.success).toBe(false); + if (!result.success) { + expect(result.error.issues[0].message).toBe( + "Path can't exceed 255 characters" + ); + } + }); + }); +}); + describe("ProjectNewRedirectPath", () => { test("accepts relative paths", () => { expect(ProjectNewRedirectPath.safeParse("/about").success).toBe(true); diff --git a/packages/sdk/src/schema/pages.ts b/packages/sdk/src/schema/pages.ts index 90ba2cf84f4b..27b8fff5c9d6 100644 --- a/packages/sdk/src/schema/pages.ts +++ b/packages/sdk/src/schema/pages.ts @@ -109,7 +109,8 @@ const DefaultPagePage = z // And we cannot customize it due to bug in Remix: https://github.com/remix-run/remix/issues/2933 (path) => path !== "/build" && path.startsWith("/build/") === false, "/build prefix is reserved for the system" - ); + ) + .refine((path) => path.length <= 255, "Path can't exceed 255 characters"); export const OldPagePath = z .string()