mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(settings): validate git identity emails only on the request path
A stored identity email that failed the stricter rule made every settings read fall back to defaults, and the next save persisted that reset. - the stored preferences schema accepts any email string again - PATCH /api/settings rejects an invalid gitIdentity or gitIdentities email with a field path, and saves the trimmed address - the rule accepts local hosts such as root@localhost
This commit is contained in:
1 parent
d089dde466
commit
0c4c024dcc
4 files changed
+157
-17
No files matched your search
@@ -124,12 +124,8 @@ export const GitCredentialSchema = z.object({
|
||||
|
||||
export type GitCredential = z.infer<typeof GitCredentialSchema>;
|
||||
|
||||
const GIT_IDENTITY_EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
const GIT_IDENTITY_EMAIL_PATTERN = /^[^\s@<>]+@[^\s@<>]+$/;
|
||||
|
||||
/**
|
||||
* A git identity email is valid when it is blank or a plain `local@domain` address. Blank is allowed because the
|
||||
* default identity starts without an email.
|
||||
*/
|
||||
export function isValidGitIdentityEmail(email: string): boolean {
|
||||
const trimmed = email.trim();
|
||||
return trimmed === "" || GIT_IDENTITY_EMAIL_PATTERN.test(trimmed);
|
||||
@@ -137,7 +133,7 @@ export function isValidGitIdentityEmail(email: string): boolean {
|
||||
|
||||
export const GitIdentitySchema = z.object({
|
||||
name: z.string(),
|
||||
email: z.string().trim().refine(isValidGitIdentityEmail, "Invalid email address"),
|
||||
email: z.string(),
|
||||
});
|
||||
|
||||
export type GitIdentity = z.infer<typeof GitIdentitySchema>;
|
||||
|
||||
Reference in new issue
Block a user