From 6f306e1259baed154b9ea20215d6f741366cde8b Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Thu, 2 Jun 2022 11:44:52 +0200 Subject: [PATCH] [PT Run][Folder]Support for paths with / (#18520) --- .../InternalQueryFolderTests.cs | 1 + .../Microsoft.Plugin.Folder/Sources/Path/FolderHelper.cs | 4 +++- .../Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/InternalQueryFolderTests.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/InternalQueryFolderTests.cs index b73908c750..ee638cbeff 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/InternalQueryFolderTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/InternalQueryFolderTests.cs @@ -52,6 +52,7 @@ namespace Microsoft.Plugin.Folder.UnitTests [DataRow(@"c:\not-exist", 2, 1, false, DisplayName = "Folder not exist, return root")] [DataRow(@"c:\not-exist\not-exist2", 0, 0, false, DisplayName = "Folder not exist, return root")] [DataRow(@"c:\bla.t", 2, 1, false, DisplayName = "Partial match file")] + [DataRow(@"c:/bla.t", 2, 1, false, DisplayName = "Partial match file with /")] public void Query_WhenCalled(string search, int folders, int files, bool truncated) { const int maxFolderSetting = 3; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Path/FolderHelper.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Path/FolderHelper.cs index 847e80587a..1a4c88e245 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Path/FolderHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Path/FolderHelper.cs @@ -84,7 +84,9 @@ namespace Microsoft.Plugin.Folder.Sources throw new ArgumentNullException(nameof(search)); } - if (search[0] == '\\' && (search.Length == 1 || search[1] != '\\')) + var validRoots = new char[] { '\\', '/' }; + + if (validRoots.Contains(search[0]) && (search.Length == 1 || !validRoots.Contains(search[1]))) { // Absolute path of system drive: \Windows\System32 search = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), search.Substring(1)); diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs index 6160337893..edd408dfd6 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/QueryInternalDirectory.cs @@ -52,7 +52,7 @@ namespace Microsoft.Plugin.Folder.Sources { // if folder doesn't exist, we want to take the last part and use it afterwards to help the user // find the right folder. - int index = search.LastIndexOf('\\'); + int index = search.LastIndexOfAny(new char[] { '\\', '/' }); // No slashes found, so probably not a folder if (index <= 0 || index >= search.Length - 1)