Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse Settings editor regular expressions more thoroughly #201248

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,30 @@ function valueValidatesAsType(value: any, type: string): boolean {
return true;
}

function toRegExp(pattern: string): RegExp {
try {
// The u flag allows support for better Unicode matching,
// but deprecates some patterns such as [\s-9]
// Ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class#description
return new RegExp(pattern, 'u');
} catch (e) {
try {
return new RegExp(pattern);
} catch (e) {
// If the pattern can't be parsed even without the 'u' flag,
// just log the error to avoid rendering the entire Settings editor blank.
// Ref https://github.com/microsoft/vscode/issues/195054
console.error(nls.localize('regexParsingError', "Error parsing the following regex both with and without the u flag:"), pattern);
return /.*/;
}
}
}

function getStringValidators(prop: IConfigurationPropertySchema) {
const uriRegex = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
let patternRegex: RegExp | undefined;
if (typeof prop.pattern === 'string') {
patternRegex = new RegExp(prop.pattern, 'u');
patternRegex = toRegExp(prop.pattern);
}

return [
Expand Down Expand Up @@ -272,7 +291,7 @@ function getArrayValidator(prop: IConfigurationPropertySchema): ((value: any) =>
}

if (typeof propItems.pattern === 'string') {
const patternRegex = new RegExp(propItems.pattern, 'u');
const patternRegex = toRegExp(propItems.pattern);
arrayValue.forEach(v => {
if (!patternRegex.test(v)) {
message +=
Expand Down