feat: booking URL validation to accept links without explicit mention of https:// (#21110)
* fix: trigger lingo.dev by removing duplicate value * feat: allow urls without an explicit https:// * fixed the test that ensures malformed URLs like "http:/nope" are rejected --------- Co-authored-by: Tushar Bhatt <[email protected]>
This commit is contained in:
1 parent
4bee875a8c
commit
d6a17b2b1e
2 files changed
+60
-2
No files matched your search
@@ -403,12 +403,31 @@ export const fieldTypesSchemaMap: Partial<
|
||||
const value = response ?? "";
|
||||
const urlSchema = z.string().url();
|
||||
|
||||
if (!urlSchema.safeParse(value).success) {
|
||||
// Check for malformed protocols (missing second slash test case)
|
||||
if (value.match(/^https?:\/[^\/]/)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: m("url_validation_error"),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Try validating the original value
|
||||
if (urlSchema.safeParse(value).success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. If it failed, try prepending https://
|
||||
const valueWithHttps = `https://${value}`;
|
||||
if (urlSchema.safeParse(valueWithHttps).success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. If all attempts fail, throw err
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: m("url_validation_error"),
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user