Add validation for empty pattern in custom editor labels (#208809)

Add validation for custom editor label patterns fixes #208723
This commit is contained in:
Benjamin Christopher Simmonds 2024-03-26 17:43:13 +01:00 committed by GitHub
parent 0c5078aacd
commit 9d8c22a86c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View file

@ -109,6 +109,8 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
{
type: 'string',
markdownDescription: localize('workbench.editor.label.template', "The template which should be rendered when the pattern mtches. May include the variables ${dirname}, ${filename} and ${extname}."),
minLength: 1,
pattern: '.*[a-zA-Z0-9].*'
},
'default': {}
},

View file

@ -74,12 +74,17 @@ export class CustomEditorLabelService extends Disposable implements ICustomEdito
this.enabled = this.configurationService.getValue<boolean>(CustomEditorLabelService.SETTING_ID_ENABLED);
}
private _templateRegexValidation: RegExp = /[a-zA-Z0-9]/;
private storeCustomPatterns(): void {
this.patterns = [];
const customLabelPatterns = this.configurationService.getValue<ICustomEditorLabelObject>(CustomEditorLabelService.SETTING_ID_PATTERNS);
for (const pattern in customLabelPatterns) {
const template = customLabelPatterns[pattern];
if (!this._templateRegexValidation.test(template)) {
continue;
}
const isAbsolutePath = isAbsolute(pattern);
const parsedPattern = parseGlob(pattern);