Skip to content

Commit 24367a8

Browse files
move checking to when env vars are constructed
1 parent 70980b9 commit 24367a8

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

lib/analysis-paths.js

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analysis-paths.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analysis-paths.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ function isInterpretedLanguage(language): boolean {
66
return language === 'javascript' || language === 'python';
77
}
88

9+
// Matches a string containing only characters that are legal to include in paths on windows.
10+
export const legalWindowsPathCharactersRegex = /^[^<>:"\|?]*$/;
11+
912
// Builds an environment variable suitable for LGTM_INDEX_INCLUDE or LGTM_INDEX_EXCLUDE
1013
function buildIncludeExcludeEnvVar(paths: string[]): string {
11-
return paths.filter(p => p.indexOf('**') === -1).join('\n');
14+
// Ignore anything containing a *
15+
paths = paths.filter(p => p.indexOf('*') === -1);
16+
17+
// Some characters are illegal in path names in windows
18+
if (process.platform === 'win32') {
19+
paths = paths.filter(p => p.match(legalWindowsPathCharactersRegex));
20+
}
21+
22+
return paths.join('\n');
1223
}
1324

1425
export function includeAndExcludeAnalysisPaths(config: configUtils.Config, languages: string[]) {

src/config-utils.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ const pathStarsRegex = /.*(?:\*\*[^/].*|\*\*$|[^/]\*\*.*)/;
122122
// See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
123123
const filterPatternCharactersRegex = /.*[\?\+\[\]!].*/;
124124

125-
// Matches any string containing characters that are illegal to include in paths on windows.
126-
export const illegalWindowsCharactersRegex = /.*[<>:"\|?*].*/;
127-
128125
// Checks that a paths of paths-ignore entry is valid, possibly modifying it
129126
// to make it valid, or if not possible then throws an error.
130127
export function validateAndSanitisePath(
@@ -161,13 +158,7 @@ export function validateAndSanitisePath(
161158
configFile,
162159
propertyName,
163160
'"' + originalPath + '" contains an unsupported character. ' +
164-
'The filter pattern characteres ?, +, [, ], ! are not supported and will be matched literally.'));
165-
}
166-
167-
// Check for any characters that are illegal in path names in windows
168-
if (process.platform === 'win32' && path.match(illegalWindowsCharactersRegex)) {
169-
throw new Error('"' + path + '" contains an invalid character. ' +
170-
'The characteres <, >, :, ", !, |, ?, * are forbidden to use in paths on windows.');
161+
'The filter pattern characters ?, +, [, ], ! are not supported and will be matched literally.'));
171162
}
172163

173164
return path;

0 commit comments

Comments
 (0)