File tree Expand file tree Collapse file tree 5 files changed +25
-1
lines changed Expand file tree Collapse file tree 5 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -10,5 +10,7 @@ describe('getPattern', () => {
10
10
expect ( getPattern ( '\\' ) ) . toEqual ( '\\\\' ) ;
11
11
expect ( getPattern ( '\\/' ) ) . toEqual ( '\\\\/' ) ;
12
12
expect ( getPattern ( '\\/\\/' ) ) . toEqual ( '\\\\/\\\\/' ) ;
13
+ // eslint-disable-next-line prettier/prettier
14
+ expect ( getPattern ( "'" ) ) . toEqual ( "\\'" ) ;
13
15
} ) ;
14
16
} ) ;
Original file line number Diff line number Diff line change 3
3
* However, to use it in HTML or inside new RegExp() we need to
4
4
* escape the pattern to become: '^\\d{3}-\\d{2}-\\d{4}$' in order
5
5
* to make it a valid regexp string.
6
+ *
7
+ * Also, escape single quote characters, because the output uses single quotes for strings
8
+ *
6
9
* @param pattern
7
10
*/
8
11
export const getPattern = ( pattern ?: string ) : string | undefined => {
9
- return pattern ?. replace ( / \\ / g, '\\\\' ) ;
12
+ // eslint-disable-next-line prettier/prettier
13
+ return pattern ?. replace ( / \\ / g, '\\\\' ) . replace ( / ' / g, "\\'" ) ;
10
14
} ;
Original file line number Diff line number Diff line change @@ -1299,6 +1299,7 @@ export type ModelWithPattern = {
1299
1299
readonly modified?: string;
1300
1300
id?: string;
1301
1301
text?: string;
1302
+ patternWithSingleQuotes?: string;
1302
1303
};
1303
1304
1304
1305
"
@@ -2090,6 +2091,10 @@ export const $ModelWithPattern = {
2090
2091
type: 'string',
2091
2092
pattern: '^\\\\\\\\w+$',
2092
2093
},
2094
+ patternWithSingleQuotes: {
2095
+ type: 'string',
2096
+ pattern: '^[a-zA-Z0-9\\\\']*$',
2097
+ },
2093
2098
},
2094
2099
} as const;
2095
2100
"
@@ -4695,6 +4700,7 @@ export type ModelWithPattern = {
4695
4700
readonly modified?: string;
4696
4701
id?: string;
4697
4702
text?: string;
4703
+ patternWithSingleQuotes?: string;
4698
4704
};
4699
4705
4700
4706
"
@@ -5931,6 +5937,10 @@ export const $ModelWithPattern = {
5931
5937
type: 'string',
5932
5938
pattern: '^\\\\\\\\w+$',
5933
5939
},
5940
+ patternWithSingleQuotes: {
5941
+ type: 'string',
5942
+ pattern: '^[a-zA-Z0-9\\\\']*$',
5943
+ },
5934
5944
},
5935
5945
} as const;
5936
5946
"
Original file line number Diff line number Diff line change 1499
1499
"text" : {
1500
1500
"type" : " string" ,
1501
1501
"pattern" : " ^\\ w+$"
1502
+ },
1503
+ "patternWithSingleQuotes" : {
1504
+ "type" : " string" ,
1505
+ "pattern" : " ^[a-zA-Z0-9']*$"
1502
1506
}
1503
1507
}
1504
1508
}
Original file line number Diff line number Diff line change 2466
2466
"text" : {
2467
2467
"type" : " string" ,
2468
2468
"pattern" : " ^\\ w+$"
2469
+ },
2470
+ "patternWithSingleQuotes" : {
2471
+ "type" : " string" ,
2472
+ "pattern" : " ^[a-zA-Z0-9']*$"
2469
2473
}
2470
2474
}
2471
2475
},
You can’t perform that action at this time.
0 commit comments