File tree Expand file tree Collapse file tree 20 files changed +26
-42
lines changed Expand file tree Collapse file tree 20 files changed +26
-42
lines changed Original file line number Diff line number Diff line change @@ -527,21 +527,12 @@ const stringTypeToZodSchema = ({
527
527
}
528
528
529
529
if ( schema . pattern ) {
530
- const text = schema . pattern
531
- . replace ( / \\ / g, '\\\\' ) // backslashes
532
- . replace ( / \n / g, '\\n' ) // newlines
533
- . replace ( / \r / g, '\\r' ) // carriage returns
534
- . replace ( / \t / g, '\\t' ) // tabs
535
- . replace ( / \f / g, '\\f' ) // form feeds
536
- . replace ( / \v / g, '\\v' ) // vertical tabs
537
- . replace ( / ' / g, "\\'" ) // single quotes
538
- . replace ( / " / g, '\\"' ) ; // double quotes
539
530
stringExpression = compiler . callExpression ( {
540
531
functionName : compiler . propertyAccessExpression ( {
541
532
expression : stringExpression ,
542
533
name : regexIdentifier ,
543
534
} ) ,
544
- parameters : [ compiler . regularExpressionLiteral ( { text } ) ] ,
535
+ parameters : [ compiler . regularExpressionLiteral ( { text : schema . pattern } ) ] ,
545
536
} ) ;
546
537
}
547
538
Original file line number Diff line number Diff line change @@ -604,8 +604,7 @@ export const ModelWithPatternSchema = {
604
604
} ,
605
605
patternWithNewline : {
606
606
type : 'string' ,
607
- pattern : `aaa
608
- bbb`
607
+ pattern : 'aaa\\nbbb'
609
608
} ,
610
609
patternWithBacktick : {
611
610
type : 'string' ,
Original file line number Diff line number Diff line change @@ -227,9 +227,9 @@ export const zModelWithPattern = z.object({
227
227
name : z . string ( ) . max ( 255 ) ,
228
228
enabled : z . boolean ( ) . readonly ( ) . optional ( ) ,
229
229
modified : z . string ( ) . datetime ( ) . readonly ( ) . optional ( ) ,
230
- id : z . string ( ) . regex ( / ^ \\ d { 2 } - \\ d { 3 } - \ \d { 4 } $ / ) . optional ( ) ,
231
- text : z . string ( ) . regex ( / ^ \\ w + $ / ) . optional ( ) ,
232
- patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 \ '] * $ / ) . optional ( ) ,
230
+ id : z . string ( ) . regex ( / ^ \d { 2 } - \d { 3 } - \d { 4 } $ / ) . optional ( ) ,
231
+ text : z . string ( ) . regex ( / ^ \w + $ / ) . optional ( ) ,
232
+ patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 ' ] * $ / ) . optional ( ) ,
233
233
patternWithNewline : z . string ( ) . regex ( / a a a \n b b b / ) . optional ( ) ,
234
234
patternWithBacktick : z . string ( ) . regex ( / a a a ` b b b / ) . optional ( )
235
235
} ) ;
Original file line number Diff line number Diff line change @@ -1204,8 +1204,7 @@ export const ModelWithPatternSchema = {
1204
1204
} ,
1205
1205
patternWithNewline : {
1206
1206
type : 'string' ,
1207
- pattern : `aaa
1208
- bbb`
1207
+ pattern : 'aaa\\nbbb'
1209
1208
} ,
1210
1209
patternWithBacktick : {
1211
1210
type : 'string' ,
Original file line number Diff line number Diff line change @@ -462,9 +462,9 @@ export const zModelWithPattern = z.object({
462
462
name : z . string ( ) . max ( 255 ) ,
463
463
enabled : z . boolean ( ) . readonly ( ) . optional ( ) ,
464
464
modified : z . string ( ) . datetime ( ) . readonly ( ) . optional ( ) ,
465
- id : z . string ( ) . regex ( / ^ \\ d { 2 } - \\ d { 3 } - \ \d { 4 } $ / ) . optional ( ) ,
466
- text : z . string ( ) . regex ( / ^ \\ w + $ / ) . optional ( ) ,
467
- patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 \ '] * $ / ) . optional ( ) ,
465
+ id : z . string ( ) . regex ( / ^ \d { 2 } - \d { 3 } - \d { 4 } $ / ) . optional ( ) ,
466
+ text : z . string ( ) . regex ( / ^ \w + $ / ) . optional ( ) ,
467
+ patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 ' ] * $ / ) . optional ( ) ,
468
468
patternWithNewline : z . string ( ) . regex ( / a a a \n b b b / ) . optional ( ) ,
469
469
patternWithBacktick : z . string ( ) . regex ( / a a a ` b b b / ) . optional ( )
470
470
} ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
5
5
export const zFoo : z . ZodTypeAny = z . union ( [
6
6
z . object ( {
7
- foo : z . string ( ) . regex ( / ^ \\ d { 3 } - \\ d { 2 } - \ \d { 4 } $ / ) . optional ( ) ,
7
+ foo : z . string ( ) . regex ( / ^ \d { 3 } - \d { 2 } - \d { 4 } $ / ) . optional ( ) ,
8
8
bar : z . object ( {
9
9
foo : z . lazy ( ( ) => {
10
10
return zFoo ;
Original file line number Diff line number Diff line change @@ -1194,8 +1194,7 @@ export const ModelWithPatternSchema = {
1194
1194
} ,
1195
1195
patternWithNewline : {
1196
1196
type : 'string' ,
1197
- pattern : `aaa
1198
- bbb`
1197
+ pattern : 'aaa\\nbbb'
1199
1198
} ,
1200
1199
patternWithBacktick : {
1201
1200
type : 'string' ,
Original file line number Diff line number Diff line change @@ -457,9 +457,9 @@ export const zModelWithPattern = z.object({
457
457
name : z . string ( ) . max ( 255 ) ,
458
458
enabled : z . boolean ( ) . readonly ( ) . optional ( ) ,
459
459
modified : z . string ( ) . datetime ( ) . readonly ( ) . optional ( ) ,
460
- id : z . string ( ) . regex ( / ^ \\ d { 2 } - \\ d { 3 } - \ \d { 4 } $ / ) . optional ( ) ,
461
- text : z . string ( ) . regex ( / ^ \\ w + $ / ) . optional ( ) ,
462
- patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 \ '] * $ / ) . optional ( ) ,
460
+ id : z . string ( ) . regex ( / ^ \d { 2 } - \d { 3 } - \d { 4 } $ / ) . optional ( ) ,
461
+ text : z . string ( ) . regex ( / ^ \w + $ / ) . optional ( ) ,
462
+ patternWithSingleQuotes : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 ' ] * $ / ) . optional ( ) ,
463
463
patternWithNewline : z . string ( ) . regex ( / a a a \n b b b / ) . optional ( ) ,
464
464
patternWithBacktick : z . string ( ) . regex ( / a a a ` b b b / ) . optional ( )
465
465
} ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
5
5
export const zFoo : z . ZodTypeAny = z . union ( [
6
6
z . object ( {
7
- foo : z . string ( ) . regex ( / ^ \\ d { 3 } - \\ d { 2 } - \ \d { 4 } $ / ) . optional ( ) ,
7
+ foo : z . string ( ) . regex ( / ^ \d { 3 } - \d { 2 } - \d { 4 } $ / ) . optional ( ) ,
8
8
bar : z . object ( {
9
9
foo : z . lazy ( ( ) => {
10
10
return zFoo ;
Original file line number Diff line number Diff line change @@ -602,8 +602,7 @@ export const ModelWithPatternSchema = {
602
602
},
603
603
patternWithNewline: {
604
604
type: ' string' ,
605
- pattern: ` aaa
606
- bbb`
605
+ pattern: ' aaa\\ nbbb'
607
606
},
608
607
patternWithBacktick: {
609
608
type: ' string' ,
You can’t perform that action at this time.
0 commit comments