Skip to content

Commit 40949f2

Browse files
authored
Merge pull request #3146 from Dokploy/3013-trim-domain-input-in-server-domain-assignation
feat: enhance domain validation by trimming whitespace from host input
2 parents b150565 + fe7a73b commit 40949f2

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

apps/dokploy/components/dashboard/application/domains/handle-domain.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ export type CacheType = "fetch" | "cache";
4646

4747
export const domain = z
4848
.object({
49-
host: z.string().min(1, { message: "Add a hostname" }),
49+
host: z
50+
.string()
51+
.min(1, { message: "Add a hostname" })
52+
.refine((val) => val === val.trim(), {
53+
message: "Domain name cannot have leading or trailing spaces",
54+
})
55+
.transform((val) => val.trim()),
5056
path: z.string().min(1).optional(),
5157
internalPath: z.string().optional(),
5258
stripPath: z.boolean().optional(),

apps/dokploy/server/db/validations/domain.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { z } from "zod";
22

33
export const domain = z
44
.object({
5-
host: z.string().min(1, { message: "Add a hostname" }),
5+
host: z
6+
.string()
7+
.min(1, { message: "Add a hostname" })
8+
.refine((val) => val === val.trim(), {
9+
message: "Domain name cannot have leading or trailing spaces",
10+
})
11+
.transform((val) => val.trim()),
612
path: z.string().min(1).optional(),
713
port: z
814
.number()
@@ -33,7 +39,13 @@ export const domain = z
3339

3440
export const domainCompose = z
3541
.object({
36-
host: z.string().min(1, { message: "Host is required" }),
42+
host: z
43+
.string()
44+
.min(1, { message: "Add a hostname" })
45+
.refine((val) => val === val.trim(), {
46+
message: "Domain name cannot have leading or trailing spaces",
47+
})
48+
.transform((val) => val.trim()),
3749
path: z.string().min(1).optional(),
3850
port: z
3951
.number()

packages/server/src/db/validations/domain.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { z } from "zod";
22

33
export const domain = z
44
.object({
5-
host: z.string().min(1, { message: "Add a hostname" }),
5+
host: z
6+
.string()
7+
.min(1, { message: "Add a hostname" })
8+
.refine((val) => val === val.trim(), {
9+
message: "Domain name cannot have leading or trailing spaces",
10+
})
11+
.transform((val) => val.trim()),
612
path: z.string().min(1).optional(),
713
internalPath: z.string().optional(),
814
stripPath: z.boolean().optional(),
@@ -58,7 +64,13 @@ export const domain = z
5864

5965
export const domainCompose = z
6066
.object({
61-
host: z.string().min(1, { message: "Host is required" }),
67+
host: z
68+
.string()
69+
.min(1, { message: "Add a hostname" })
70+
.refine((val) => val === val.trim(), {
71+
message: "Domain name cannot have leading or trailing spaces",
72+
})
73+
.transform((val) => val.trim()),
6274
path: z.string().min(1).optional(),
6375
internalPath: z.string().optional(),
6476
stripPath: z.boolean().optional(),

packages/server/src/services/domain.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const createDomain = async (input: typeof apiCreateDomain._type) => {
1919
.insert(domains)
2020
.values({
2121
...input,
22+
host: input.host?.trim(),
2223
})
2324
.returning()
2425
.then((response) => response[0]);
@@ -120,6 +121,7 @@ export const updateDomainById = async (
120121
.update(domains)
121122
.set({
122123
...domainData,
124+
...(domainData.host && { host: domainData.host.trim() }),
123125
})
124126
.where(eq(domains.domainId, domainId))
125127
.returning();

0 commit comments

Comments
 (0)