fix: replace z.string().email() with RFC 5322 compliant zEmail() (#2656)

This commit is contained in:
Lucas Smith
2026-03-26 16:31:21 +11:00
committed by GitHub
parent 814f6e62de
commit 2346de83a6
36 changed files with 90 additions and 97 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ import {
ZTextFieldMeta,
} from '@documenso/lib/types/field-meta';
import { toCheckboxCustomText, toRadioCustomText } from '@documenso/lib/utils/fields';
import { ZEmail } from '@documenso/lib/utils/zod';
import { zEmail } from '@documenso/lib/utils/zod';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { checkboxValidationSigns } from '@documenso/ui/primitives/document-flow/field-items-advanced-settings/constants';
@@ -38,7 +38,7 @@ export const extractFieldInsertionValues = ({
}: ExtractFieldInsertionValuesOptions): { customText: string; inserted: boolean } => {
return match(fieldValue)
.with({ type: FieldType.EMAIL }, (fieldValue) => {
const parsedEmailValue = ZEmail.nullable().safeParse(fieldValue.value);
const parsedEmailValue = zEmail().nullable().safeParse(fieldValue.value);
if (!parsedEmailValue.success) {
throw new AppError(AppErrorCode.INVALID_BODY, {
+2 -2
View File
@@ -6,7 +6,7 @@ import { isSignatureFieldType } from '@documenso/prisma/guards/is-signature-fiel
import { NEXT_PUBLIC_WEBAPP_URL } from '../constants/app';
import { AppError, AppErrorCode } from '../errors/app-error';
import { extractLegacyIds } from '../universal/id';
import { ZEmail } from './zod';
import { zEmail } from './zod';
/**
* Roles that require fields to be assigned before a document can be distributed.
@@ -93,7 +93,7 @@ export const mapRecipientToLegacyRecipient = (
};
export const isRecipientEmailValidForSending = (recipient: Pick<Recipient, 'email'>) => {
return ZEmail.safeParse(recipient.email).success;
return zEmail().safeParse(recipient.email).success;
};
/**
+6 -13
View File
@@ -14,27 +14,20 @@ const EMAIL_REGEX =
const DEFAULT_EMAIL_MESSAGE = 'Invalid email address';
/**
* A Zod schema for validating email addresses using an RFC 5322 compliant regex.
* Creates a Zod email schema using an RFC 5322 compliant regex.
*
* This supports international characters in the local part and domain
* Supports international characters in the local part and domain
* (e.g. "Søren@gmail.com", "user@dömain.com").
*
* Use `zEmail()` if you need to pass a custom error message.
*/
export const ZEmail = z.string().regex(EMAIL_REGEX, { message: DEFAULT_EMAIL_MESSAGE });
/**
* Creates a Zod email schema with an optional custom error message.
* Returns a standard `ZodString` so all string methods are chainable:
* `.min()`, `.max()`, `.trim()`, `.toLowerCase()`, `.optional()`, `.nullish()`, etc.
*
* @example
* ```ts
* // With default message
* zEmail()
*
* // With custom message string
* zEmail().min(1).max(254)
* zEmail().trim().toLowerCase()
* zEmail('Email is invalid')
*
* // With message object
* zEmail({ message: 'Email is invalid' })
* ```
*/