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 @@ -1298,6 +1298,7 @@ export type ModelWithPattern = {
1298
1298
readonly modified?: string;
1299
1299
id?: string;
1300
1300
text?: string;
1301
+ patternWithSingleQuotes?: string;
1301
1302
};
1302
1303
1303
1304
"
@@ -2089,6 +2090,10 @@ export const $ModelWithPattern = {
2089
2090
type: 'string',
2090
2091
pattern: '^\\\\\\\\w+$',
2091
2092
},
2093
+ patternWithSingleQuotes: {
2094
+ type: 'string',
2095
+ pattern: '^[a-zA-Z0-9\\\\']*$',
2096
+ },
2092
2097
},
2093
2098
} as const;
2094
2099
"
@@ -4693,6 +4698,7 @@ export type ModelWithPattern = {
4693
4698
readonly modified?: string;
4694
4699
id?: string;
4695
4700
text?: string;
4701
+ patternWithSingleQuotes?: string;
4696
4702
};
4697
4703
4698
4704
"
@@ -5929,6 +5935,10 @@ export const $ModelWithPattern = {
5929
5935
type: 'string',
5930
5936
pattern: '^\\\\\\\\w+$',
5931
5937
},
5938
+ patternWithSingleQuotes: {
5939
+ type: 'string',
5940
+ pattern: '^[a-zA-Z0-9\\\\']*$',
5941
+ },
5932
5942
},
5933
5943
} as const;
5934
5944
"
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