From 37f2789e390015af64d67c13faaeb41b57666153 Mon Sep 17 00:00:00 2001 From: "Tyler Leonhardt (POWERSHELL)" Date: Mon, 10 Aug 2020 15:38:47 -0700 Subject: [PATCH] Fix references on Windows due to slashes --- .../Services/Workspace/WorkspaceService.cs | 5 +++- .../Session/WorkspaceTests.cs | 24 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs index b9fa7f018..785264cdf 100644 --- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs +++ b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs @@ -406,7 +406,10 @@ bool ignoreReparsePoints var fileMatchResult = matcher.Execute(fsFactory.RootDirectory); foreach (FilePatternMatch item in fileMatchResult.Files) { - yield return Path.Combine(WorkspacePath, item.Path); + // item.Path always contains forward slashes in paths when it should be backslashes on Windows. + // Since we're returning strings here, it's important to use the correct directory separator. + var path = VersionUtils.IsWindows ? item.Path.Replace('/', Path.DirectorySeparatorChar) : item.Path; + yield return Path.Combine(WorkspacePath, path); } } diff --git a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs index 73105a75c..8b7042e19 100644 --- a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs +++ b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs @@ -103,19 +103,19 @@ public void CanRecurseDirectoryTree() // suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1' // 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_ Assert.Equal(4, fileList.Count); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/donotfind.ps1", fileList[0]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[1]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psm1", fileList[2]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[3]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[3]); } else { Assert.Equal(5, fileList.Count); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/donotfind.ps1", fileList[0]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[1]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psm1", fileList[2]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"other") + "/other.ps1xml", fileList[3]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[4]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "donotfind.ps1"), fileList[0]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[1]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psm1"), fileList[2]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "other", "other.ps1xml"), fileList[3]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[4]); } } @@ -133,7 +133,7 @@ public void CanRecurseDirectoryTreeWithLimit() ); Assert.Equal(1, fileList.Count); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[0]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[0]); } [Fact] @@ -150,8 +150,8 @@ public void CanRecurseDirectoryTreeWithGlobs() ); Assert.Equal(2, fileList.Count); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested") + "/nestedmodule.psd1", fileList[0]); - Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[1]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "nested", "nestedmodule.psd1"), fileList[0]); + Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[1]); } [Fact]