Skip to content

Commit 47cf7ca

Browse files
committed
Fix path escaping and slash normalization
1 parent 439f1c7 commit 47cf7ca

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/server/editorServices.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,10 +1454,12 @@ namespace ts.server {
14541454

14551455
const excludeRules: string[] = [];
14561456

1457+
const normalizedNames = rootFiles.map(f => normalizeSlashes(f.fileName));
1458+
14571459
for (const name of Object.keys(ProjectService.safelist)) {
14581460
const rule = ProjectService.safelist[name];
1459-
for (const root of rootFiles) {
1460-
if (rule.match.test(root.fileName)) {
1461+
for (const root of normalizedNames) {
1462+
if (rule.match.test(root)) {
14611463
this.logger.info(`Excluding files based on rule ${name}`);
14621464

14631465
// If the file matches, collect its types packages and exclude rules
@@ -1471,7 +1473,7 @@ namespace ts.server {
14711473

14721474
if (rule.exclude) {
14731475
for (const exclude of rule.exclude) {
1474-
const processedRule = root.fileName.replace(rule.match, (...groups: Array<string>) => {
1476+
const processedRule = root.replace(rule.match, (...groups: Array<string>) => {
14751477
return exclude.map(groupNumberOrString => {
14761478
// RegExp group numbers are 1-based, but the first element in groups
14771479
// is actually the original string, so it all works out in the end.
@@ -1488,15 +1490,16 @@ namespace ts.server {
14881490
}).join("");
14891491
});
14901492

1491-
if (excludeRules.indexOf(processedRule) == -1) {
1493+
if (excludeRules.indexOf(processedRule) === -1) {
14921494
excludeRules.push(processedRule);
14931495
}
14941496
}
14951497
}
14961498
else {
14971499
// If not rules listed, add the default rule to exclude the matched file
1498-
if (excludeRules.indexOf(root.fileName) < 0) {
1499-
excludeRules.push(root.fileName);
1500+
const escaped = ProjectService.escapeFilenameForRegex(root);
1501+
if (excludeRules.indexOf(escaped) < 0) {
1502+
excludeRules.push(escaped);
15001503
}
15011504
}
15021505
}
@@ -1510,7 +1513,7 @@ namespace ts.server {
15101513
}
15111514

15121515
const excludeRegexes = excludeRules.map(e => new RegExp(e, "i"));
1513-
proj.rootFiles = proj.rootFiles.filter(file => !excludeRegexes.some(re => re.test(file.fileName)));
1516+
proj.rootFiles = proj.rootFiles.filter((_file, index) => !excludeRegexes.some(re => re.test(normalizedNames[index])));
15141517
}
15151518

15161519
openExternalProject(proj: protocol.ExternalProject, suppressRefreshOfInferredProjects = false): void {

0 commit comments

Comments
 (0)