Skip to content

Commit 8d7b806

Browse files
committed
fixes
1 parent 4245794 commit 8d7b806

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, it, expect } from 'vitest';
2+
import {
3+
projectWorkspaceNameRegex,
4+
managedControlPlaneNameRegex,
5+
} from './regex';
6+
7+
describe('projectWorkspaceNameRegex', () => {
8+
const valid = [
9+
'Project1',
10+
'my-project',
11+
'A1-B2-C3',
12+
'abc.DEF-123',
13+
'a'.repeat(63),
14+
'abc.def.ghi',
15+
'A-1.b-2',
16+
'abc123',
17+
'abc-123.DEF',
18+
];
19+
const invalid = [
20+
'-project',
21+
'project-',
22+
'.project',
23+
'project.',
24+
'a'.repeat(64),
25+
'abc..def',
26+
'abc.-def',
27+
'abc-.def',
28+
'abc_def',
29+
'abc@def',
30+
];
31+
32+
it('matches valid project or workspace names', () => {
33+
for (const name of valid) {
34+
expect(projectWorkspaceNameRegex.test(name)).toBe(true);
35+
}
36+
});
37+
38+
it('does not match invalid project or workspace names', () => {
39+
for (const name of invalid) {
40+
expect(projectWorkspaceNameRegex.test(name)).toBe(false);
41+
}
42+
});
43+
});
44+
45+
describe('managedControlPlaneNameRegex', () => {
46+
const valid = [
47+
'my-mcp',
48+
'abc123',
49+
'abc-123',
50+
'abc.def',
51+
'a'.repeat(63),
52+
'abc.def-ghi',
53+
'abc-123.def',
54+
'abc1-2.def3',
55+
'abc.def.ghi',
56+
];
57+
const invalid = [
58+
'My-MCP',
59+
'ABC',
60+
'-mcp',
61+
'mcp-',
62+
'.mcp',
63+
'mcp.',
64+
'a'.repeat(64),
65+
'abc..def',
66+
'abc-.def',
67+
'abc.-def',
68+
];
69+
70+
it('matches valid managed control plane names', () => {
71+
for (const name of valid) {
72+
expect(managedControlPlaneNameRegex.test(name)).toBe(true);
73+
}
74+
});
75+
76+
it('does not match invalid managed control plane names', () => {
77+
for (const name of invalid) {
78+
expect(managedControlPlaneNameRegex.test(name)).toBe(false);
79+
}
80+
});
81+
});

src/lib/api/validations/regex.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const projectWorkspaceNameRegex =
2+
/^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*$/;
3+
export const managedControlPlaneNameRegex =
4+
/^(?!-)[a-z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-z0-9-]{1,63}(?<!-))*$/;

src/lib/api/validations/schemas.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { z } from 'zod';
22
import { Member } from '../types/shared/members.ts';
33
import i18n from '../../../../i18n.ts';
4+
import {
5+
managedControlPlaneNameRegex,
6+
projectWorkspaceNameRegex,
7+
} from './regex.ts';
48

59
const { t } = i18n;
610

711
const member = z.custom<Member>();
812

9-
export const projectWorkspaceNameRegex =
10-
/^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*$/;
11-
export const managedControlPlaneNameRegex =
12-
/^(?!-)[a-z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-z0-9-]{1,63}(?<!-))*$/;
13-
1413
export const validationSchemaProjectWorkspace = z.object({
1514
name: z
1615
.string()

0 commit comments

Comments
 (0)