Skip to content

Commit 5463483

Browse files
Fix reference number on Windows due to directory separator difference on Windows (#1348)
Co-authored-by: Tyler Leonhardt (POWERSHELL) <[email protected]>
1 parent f5587c1 commit 5463483

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ bool ignoreReparsePoints
406406
var fileMatchResult = matcher.Execute(fsFactory.RootDirectory);
407407
foreach (FilePatternMatch item in fileMatchResult.Files)
408408
{
409-
yield return Path.Combine(WorkspacePath, item.Path);
409+
// item.Path always contains forward slashes in paths when it should be backslashes on Windows.
410+
// Since we're returning strings here, it's important to use the correct directory separator.
411+
var path = VersionUtils.IsWindows ? item.Path.Replace('/', Path.DirectorySeparatorChar) : item.Path;
412+
yield return Path.Combine(WorkspacePath, path);
410413
}
411414
}
412415

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ public void CanRecurseDirectoryTree()
103103
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
104104
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
105105
Assert.Equal(4, fileList.Count);
106-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/donotfind.ps1", fileList[0]);
107-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[1]);
108-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psm1", fileList[2]);
109-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[3]);
106+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]);
107+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]);
108+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]);
109+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[3]);
110110
}
111111
else
112112
{
113113
Assert.Equal(5, fileList.Count);
114-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/donotfind.ps1", fileList[0]);
115-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[1]);
116-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psm1", fileList[2]);
117-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"other") + "/other.ps1xml", fileList[3]);
118-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[4]);
114+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]);
115+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]);
116+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]);
117+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "other", "other.ps1xml"), fileList[3]);
118+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[4]);
119119
}
120120
}
121121

@@ -133,7 +133,7 @@ public void CanRecurseDirectoryTreeWithLimit()
133133
);
134134

135135
Assert.Equal(1, fileList.Count);
136-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[0]);
136+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[0]);
137137
}
138138

139139
[Fact]
@@ -150,8 +150,8 @@ public void CanRecurseDirectoryTreeWithGlobs()
150150
);
151151

152152
Assert.Equal(2, fileList.Count);
153-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[0]);
154-
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[1]);
153+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[0]);
154+
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[1]);
155155
}
156156

157157
[Fact]

0 commit comments

Comments
 (0)