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:
Chris Scott committed 2026-10-23 15:45:36 -04:00
1 parent d089dde466
commit 0c4c024dcc
4 files changed
+157 -17

No files matched your search

+2 -6
View File
@@ -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>;