fix: add strict URL validation with consistent error message (#22843)
* added strict url validation with consistent Invalid URL error message * chore * Update schema.ts --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
co-authored by
Anik Dhabal Babu
parent
09b1643478
commit
736f1f594c
@@ -418,9 +418,12 @@ export const fieldTypesSchemaMap: Partial<
|
||||
}
|
||||
|
||||
// 2. If it failed, try prepending https://
|
||||
const valueWithHttps = `https://${value}`;
|
||||
if (urlSchema.safeParse(valueWithHttps).success) {
|
||||
return;
|
||||
const domainLike = /^[a-z0-9.-]+\.[a-z]{2,}(\/.*)?$/i;
|
||||
if (domainLike.test(value)) {
|
||||
const valueWithHttps = `https://${value}`;
|
||||
if (urlSchema.safeParse(valueWithHttps).success) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. If all attempts fail, throw err
|
||||
|
||||
Reference in New Issue
Block a user