move checking to when env vars are constructed

This commit is contained in:
Robert Brignull 2020-07-09 18:05:54 +01:00
parent 70980b9f32
commit 24367a89b5
6 changed files with 25 additions and 22 deletions

View file

@ -6,9 +6,20 @@ function isInterpretedLanguage(language): boolean {
return language === 'javascript' || language === 'python';
}
// Matches a string containing only characters that are legal to include in paths on windows.
export const legalWindowsPathCharactersRegex = /^[^<>:"\|?]*$/;
// Builds an environment variable suitable for LGTM_INDEX_INCLUDE or LGTM_INDEX_EXCLUDE
function buildIncludeExcludeEnvVar(paths: string[]): string {
return paths.filter(p => p.indexOf('**') === -1).join('\n');
// Ignore anything containing a *
paths = paths.filter(p => p.indexOf('*') === -1);
// Some characters are illegal in path names in windows
if (process.platform === 'win32') {
paths = paths.filter(p => p.match(legalWindowsPathCharactersRegex));
}
return paths.join('\n');
}
export function includeAndExcludeAnalysisPaths(config: configUtils.Config, languages: string[]) {

View file

@ -122,9 +122,6 @@ const pathStarsRegex = /.*(?:\*\*[^/].*|\*\*$|[^/]\*\*.*)/;
// See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
const filterPatternCharactersRegex = /.*[\?\+\[\]!].*/;
// Matches any string containing characters that are illegal to include in paths on windows.
export const illegalWindowsCharactersRegex = /.*[<>:"\|?*].*/;
// Checks that a paths of paths-ignore entry is valid, possibly modifying it
// to make it valid, or if not possible then throws an error.
export function validateAndSanitisePath(
@ -161,13 +158,7 @@ export function validateAndSanitisePath(
configFile,
propertyName,
'"' + originalPath + '" contains an unsupported character. ' +
'The filter pattern characteres ?, +, [, ], ! are not supported and will be matched literally.'));
}
// Check for any characters that are illegal in path names in windows
if (process.platform === 'win32' && path.match(illegalWindowsCharactersRegex)) {
throw new Error('"' + path + '" contains an invalid character. ' +
'The characteres <, >, :, ", !, |, ?, * are forbidden to use in paths on windows.');
'The filter pattern characters ?, +, [, ], ! are not supported and will be matched literally.'));
}
return path;