-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: zod zccepts invalid url: z.string().url().safeParse("a:")
#2477
Comments
It's because the URL is being validated with just a Probably should add checks to make sure only certain protocols (http/https?) get through, and that it has a valid, non-empty host (or just use validator.js refinement) |
@JaneJeon yeah... does not seem right to me using native URL class... I would choose validator.js for url validation really. Because with URL class we do not have any flexibility... For example class-validator uses validator.js url validation too. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still unaddressed |
Is this what you are looking for? const schema = z.string().startsWith( 'http' ).url()
console.log( schema.safeParse( 'a:' ).success ) // false
console.log( schema.safeParse( 'http:a' ).success ) // true If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Current behaviour:
I expect validation to fail there
The text was updated successfully, but these errors were encountered: