Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

feat: validate page path doesn't exceed 255 characters (#5704)

Cosimo Kroll033e37ad8b34
diff --git a/packages/sdk/src/schema/pages.test.ts b/packages/sdk/src/schema/pages.test.ts
index 14c8650159..a0ce119bc2 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 90ba2cf84f..27b8fff5c9 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()