zod
                                
                                 zod copied to clipboard
                                
                                    zod copied to clipboard
                            
                            
                            
                        zod url fails when having port number and field/value pairs
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"
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..
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
I'm opposed to changing from the existing implementation that uses URL - Zod should fall back on JavaScript built-ins whenever possible imo
@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.