Skip to content

Commit b30e0e3

Browse files
authored
fix: allow case sensitive path in redirects ( old path field ) #5079 (#5084)
fixes #5079 ## Description this fix was to allow case sensitive path in redirects (specifically the "old-path" field), for users migrating from legacy system this could be important. ![Screen Shot 2025-04-03 at 2 00 54 PM](https://github.com/user-attachments/assets/011d9026-4a54-436c-b26c-8b3300b52c5b) 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click on project setting 2. go to redirects tab 3. input a path with uppercase letter(s) in the old-path field and the page you want to redirect to 4. This should work without any error ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [x] made a self-review - [x] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [x] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 1bbfe42 commit b30e0e3

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

apps/builder/app/builder/features/project-settings/section-redirects.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Text,
1414
theme,
1515
Tooltip,
16+
truncate,
1617
} from "@webstudio-is/design-system";
1718
import { ArrowRightIcon, TrashIcon } from "@webstudio-is/icons";
1819
import {

packages/sdk/src/schema/pages.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,34 @@ const DefaultPagePage = z
110110
"/build prefix is reserved for the system"
111111
);
112112

113+
export const OldPagePath = z
114+
.string()
115+
.refine((path) => path !== "", "Can't be empty")
116+
.refine((path) => path !== "/", "Can't be just a /")
117+
.refine(
118+
(path) => path === "" || path.startsWith("/"),
119+
"Must start with a / or a full URL e.g. https://website.org"
120+
)
121+
.refine((path) => path.endsWith("/") === false, "Can't end with a /")
122+
.refine((path) => path.includes("//") === false, "Can't contain repeating /")
123+
.refine(
124+
(path) => /^[-_a-zA-Z0-9*:?\\/.]*$/.test(path), // Allow uppercase letters (A-Z)
125+
"Only a-z, A-Z, 0-9, -, _, /, :, ?, . and * are allowed"
126+
)
127+
.refine(
128+
(path) => path !== "/s" && path.startsWith("/s/") === false,
129+
"/s prefix is reserved for the system"
130+
)
131+
.refine(
132+
(path) => path !== "/build" && path.startsWith("/build/") === false,
133+
"/build prefix is reserved for the system"
134+
);
135+
113136
export const PagePath = DefaultPagePage.refine(
114137
(path) => path === "" || path.startsWith("/"),
115138
"Must start with a / or a full URL e.g. https://website.org"
116139
);
117140

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

124142
const Page = z.object({
125143
...commonPageFields,
@@ -152,7 +170,7 @@ export const ProjectNewRedirectPath = PagePath.or(
152170
);
153171

154172
export const PageRedirect = z.object({
155-
old: PagePath,
173+
old: OldPagePath,
156174
new: ProjectNewRedirectPath,
157175
status: z.enum(["301", "302"]).optional(),
158176
});

0 commit comments

Comments
 (0)