zod icon indicating copy to clipboard operation
zod copied to clipboard

zod url fails when having port number and field/value pairs

Open JacobWeisenburger opened this issue 2 years ago • 2 comments

Discussed in https://github.com/colinhacks/zod/discussions/1479

Originally posted by RicardoValero95 October 11, 2022 This url works fine "sqlserver://database-test.amazonaws.com;database=x;user=y;password=z;trustServerCertificate=true"

But this doesn't "sqlserver://192.168.100.10:1433;database=x;user=y;password=z;trustServerCertificate=true"

JacobWeisenburger avatar Dec 13 '22 15:12 JacobWeisenburger

If native URL doesn't say it is a valid url, should zod step in and have an opinion on this?

Just trying to align myself, don't take it as me questioning the validity of the issue/bug..

igalklebanov avatar Dec 13 '22 16:12 igalklebanov

Fair point. I didn't think to check that. Probs a question for @colinhacks

const schema = z.string().url()

const string1 = 'sqlserver://database-test.amazonaws.com;database=x;user=y;password=z;trustServerCertificate=true'
console.log( schema.safeParse( string1 ).success ) // true
console.log( new URL( string1 ) ) // works

const string2 = 'sqlserver://192.168.100.10:1433;database=x;user=y;password=z;trustServerCertificate=true'
console.log( schema.safeParse( string2 ).success ) // false
console.log( new URL( string2 ) ) // throws

JacobWeisenburger avatar Dec 13 '22 16:12 JacobWeisenburger

I'm opposed to changing from the existing implementation that uses URL - Zod should fall back on JavaScript built-ins whenever possible imo

colinhacks avatar Dec 13 '22 21:12 colinhacks

@colinhacks thanks for the quick response. I know you are busy and it's definitely not easy being the owner of such a popular library.

JacobWeisenburger avatar Dec 13 '22 22:12 JacobWeisenburger