Skip to content

Commit a4bb5af

Browse files
jeanp413mustard-mh
andcommitted
[PAT] Validate pat
Co-authored-by: Huiwen <[email protected]>
1 parent 84ca305 commit a4bb5af

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

components/dashboard/src/settings/PersonalAccessTokens.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ export function PersonalAccessTokenCreateView() {
152152
if (change.expirationDays) {
153153
change.expirationDate = new Date(Date.now() + change.expirationDays * 24 * 60 * 60 * 1000);
154154
}
155-
if (change.name) {
156-
if (!personalAccessTokenNameRegex.test(change.name)) {
157-
}
158-
}
159155
setErrorMsg("");
160156
setValue({ ...value, ...change });
161157
};
@@ -176,8 +172,14 @@ export function PersonalAccessTokenCreateView() {
176172
};
177173

178174
const handleConfirm = async () => {
179-
if (value.name.length < 3) {
180-
setErrorMsg("Token Name should have at least three characters.");
175+
if (/^\s+/.test(value.name) || /\s+$/.test(value.name)) {
176+
setErrorMsg("Token Name should not start or end with a space");
177+
return;
178+
}
179+
if (!personalAccessTokenNameRegex.test(value.name)) {
180+
setErrorMsg(
181+
"Token Name should have a length between 3 and 63 characters, it can only contain letters, numbers, underscore and space characters",
182+
);
181183
return;
182184
}
183185
try {

0 commit comments

Comments
 (0)