@@ -112,11 +112,30 @@ function valueValidatesAsType(value: any, type: string): boolean {
112
112
return true ;
113
113
}
114
114
115
+ function toRegExp ( pattern : string ) : RegExp {
116
+ try {
117
+ // The u flag allows support for better Unicode matching,
118
+ // but deprecates some patterns such as [\s-9]
119
+ // Ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class#description
120
+ return new RegExp ( pattern , 'u' ) ;
121
+ } catch ( e ) {
122
+ try {
123
+ return new RegExp ( pattern ) ;
124
+ } catch ( e ) {
125
+ // If the pattern can't be parsed even without the 'u' flag,
126
+ // just log the error to avoid rendering the entire Settings editor blank.
127
+ // Ref https://github.com/microsoft/vscode/issues/195054
128
+ console . error ( nls . localize ( 'regexParsingError' , "Error parsing the following regex both with and without the u flag:" ) , pattern ) ;
129
+ return / .* / ;
130
+ }
131
+ }
132
+ }
133
+
115
134
function getStringValidators ( prop : IConfigurationPropertySchema ) {
116
135
const uriRegex = / ^ ( ( [ ^ : / ? # ] + ?) : ) ? ( \/ \/ ( [ ^ / ? # ] * ) ) ? ( [ ^ ? # ] * ) ( \? ( [ ^ # ] * ) ) ? ( # ( .* ) ) ? / ;
117
136
let patternRegex : RegExp | undefined ;
118
137
if ( typeof prop . pattern === 'string' ) {
119
- patternRegex = new RegExp ( prop . pattern , 'u' ) ;
138
+ patternRegex = toRegExp ( prop . pattern ) ;
120
139
}
121
140
122
141
return [
@@ -272,7 +291,7 @@ function getArrayValidator(prop: IConfigurationPropertySchema): ((value: any) =>
272
291
}
273
292
274
293
if ( typeof propItems . pattern === 'string' ) {
275
- const patternRegex = new RegExp ( propItems . pattern , 'u' ) ;
294
+ const patternRegex = toRegExp ( propItems . pattern ) ;
276
295
arrayValue . forEach ( v => {
277
296
if ( ! patternRegex . test ( v ) ) {
278
297
message +=
0 commit comments