File tree Expand file tree Collapse file tree 5 files changed +5
-3
lines changed Expand file tree Collapse file tree 5 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -1879,7 +1879,7 @@ You can create a Zod schema for any TypeScript type by using `z.custom()`. This
1879
1879
1880
1880
``` ts
1881
1881
const px = z .custom <` ${number }px ` >((val ) => {
1882
- return / ^ \d + px$ / .test (val as string ) ;
1882
+ return typeof val === " string " ? / ^ \d + px$ / .test (val ) : false ;
1883
1883
});
1884
1884
1885
1885
type px = z .infer <typeof px >; // `${number}px`
Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ test("email validations", () => {
146
146
`gbacher0@[IPv6:bc37:4d3f:5048:2e26:37cc:248e:df8e:2f7f:af]` ,
147
147
`invalid@[IPv6:5348:4ed3:5d38:67fb:e9b:acd2:c13:192.168.256.1]` ,
148
148
`test@.com` ,
149
+ `aaaaaaaaaaaaaaalongemailthatcausesregexDoSvulnerability@test.c`
149
150
] ;
150
151
const emailSchema = z . string ( ) . email ( ) ;
151
152
Original file line number Diff line number Diff line change @@ -565,7 +565,7 @@ const uuidRegex =
565
565
// const emailRegex =
566
566
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
567
567
const emailRegex =
568
- / ^ ( [ A - Z 0 - 9 _ + - ] + \. ? ) * [ A - Z 0 - 9 _ + - ] @ ( [ A - Z 0 - 9 ] [ A - Z 0 - 9 \- ] * \. ) + [ A - Z ] { 2 , } $ / i;
568
+ / ^ (? ! \. ) (? ! . * \. \. ) ( [ A - Z 0 - 9 _ + -\. ] * ) [ A - Z 0 - 9 _ + - ] @ ( [ A - Z 0 - 9 ] [ A - Z 0 - 9 \- ] * \. ) + [ A - Z ] { 2 , } $ / i;
569
569
// const emailRegex =
570
570
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
571
571
Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ test("email validations", () => {
145
145
`gbacher0@[IPv6:bc37:4d3f:5048:2e26:37cc:248e:df8e:2f7f:af]` ,
146
146
`invalid@[IPv6:5348:4ed3:5d38:67fb:e9b:acd2:c13:192.168.256.1]` ,
147
147
`test@.com` ,
148
+ `aaaaaaaaaaaaaaalongemailthatcausesregexDoSvulnerability@test.c`
148
149
] ;
149
150
const emailSchema = z . string ( ) . email ( ) ;
150
151
Original file line number Diff line number Diff line change @@ -565,7 +565,7 @@ const uuidRegex =
565
565
// const emailRegex =
566
566
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
567
567
const emailRegex =
568
- / ^ ( [ A - Z 0 - 9 _ + - ] + \. ? ) * [ A - Z 0 - 9 _ + - ] @ ( [ A - Z 0 - 9 ] [ A - Z 0 - 9 \- ] * \. ) + [ A - Z ] { 2 , } $ / i;
568
+ / ^ (? ! \. ) (? ! . * \. \. ) ( [ A - Z 0 - 9 _ + -\. ] * ) [ A - Z 0 - 9 _ + - ] @ ( [ A - Z 0 - 9 ] [ A - Z 0 - 9 \- ] * \. ) + [ A - Z ] { 2 , } $ / i;
569
569
// const emailRegex =
570
570
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
571
571
You can’t perform that action at this time.
0 commit comments