fix: use native URL parser instead of wrong regex (#1206)

Updates the current regex based approach for validating redirect urls to 
instead use the native URL constructor which is available in browsers and 
Node.js and handles several valid cases that were previously not working.
This commit is contained in:
aeris
2024-07-31 07:26:05 +02:00
committed by GitHub
parent 0c744a1123
commit a9025b5d97
7 changed files with 38 additions and 19 deletions

View File

@ -2,11 +2,11 @@ import { z } from 'zod';
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
import { DEFAULT_DOCUMENT_TIME_ZONE } from '@documenso/lib/constants/time-zones';
import { URL_REGEX } from '@documenso/lib/constants/url-regex';
import {
ZDocumentAccessAuthTypesSchema,
ZDocumentActionAuthTypesSchema,
} from '@documenso/lib/types/document-auth';
import { isValidRedirectUrl } from '@documenso/lib/utils/is-valid-redirect-url';
export const ZMapNegativeOneToUndefinedSchema = z
.string()
@ -34,8 +34,9 @@ export const ZAddSettingsFormSchema = z.object({
redirectUrl: z
.string()
.optional()
.refine((value) => value === undefined || value === '' || URL_REGEX.test(value), {
message: 'Please enter a valid URL',
.refine((value) => value === undefined || value === '' || isValidRedirectUrl(value), {
message:
'Please enter a valid URL, make sure you include http:// or https:// part of the url.',
}),
}),
});