diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Helper/QueryHelperTest.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Helper/QueryHelperTest.cs
index d6b31f6829..585cb3a5bd 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Helper/QueryHelperTest.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Helper/QueryHelperTest.cs
@@ -17,6 +17,18 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.UnitTest.Helper
[DataRow(@"HKLM\\Test", true, @"HKLM", "Test")]
[DataRow(@"HKLM\Test\\TestTest", true, @"HKLM\Test", "TestTest")]
[DataRow(@"HKLM\Test\\\TestTest", true, @"HKLM\Test", @"\TestTest")]
+ [DataRow("HKLM/\"Software\"/", false, @"HKLM\Software\", "")]
+ [DataRow("HKLM/\"Software\"//test", true, @"HKLM\Software", "test")]
+ [DataRow("HKLM/\"Software\"//test/123", true, @"HKLM\Software", "test/123")]
+ [DataRow("HKLM/\"Software\"//test\\123", true, @"HKLM\Software", @"test\123")]
+ [DataRow("HKLM/\"Software\"/test", false, @"HKLM\Software\test", "")]
+ [DataRow("HKLM\\Software\\\"test\"", false, @"HKLM\Software\test", "")]
+ [DataRow("HKLM\\\"Software\"\\\"test\"", false, @"HKLM\Software\test", "")]
+ [DataRow("HKLM\\\"Software\"\\\"test/software\"", false, @"HKLM\Software\test/software", "")]
+ [DataRow("HKLM\\\"Software\"/\"test\"\\hello", false, @"HKLM\Software\test\hello", "")]
+ [DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
+ [DataRow("HKLM\\\"Software\"\\\"test\"/hello\\\\\"some/value\"", true, @"HKLM\Software\test\hello", "some/value")]
+ [DataRow("HKLM\\\"Software\"\\\"test\"\\hello\\\\some\\value", true, @"HKLM\Software\test\hello", @"some\value")]
public void GetQueryPartsTest(string query, bool expectedHasValueName, string expectedQueryKey, string expectedQueryValueName)
{
var hasValueName = QueryHelper.GetQueryParts(query, out var queryKey, out var queryValueName);
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/QueryHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/QueryHelper.cs
index 8b8371ff11..ed8403a3f4 100644
--- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/QueryHelper.cs
+++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/QueryHelper.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using Microsoft.PowerToys.Run.Plugin.Registry.Constants;
namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
@@ -32,6 +33,18 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
{ Win32.Registry.Users.Name, KeyName.UsersShort },
};
+ ///
+ /// Sanitize the query to avoid issues with the regex
+ ///
+ /// Query containing front-slash
+ /// A string replacing all the front-slashes with back-slashes
+ private static string SanitizeQuery(in string query)
+ {
+ var sanitizedQuery = Regex.Replace(query, @"/(?<=^(?:[^""]*""[^""]*"")*[^""]*)(?
/// Return the parts of a given query
///
@@ -41,14 +54,16 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
/// when the query search for a key and a value name, otherwise
internal static bool GetQueryParts(in string query, out string queryKey, out string queryValueName)
{
- if (!query.Contains(QuerySplitCharacter, StringComparison.InvariantCultureIgnoreCase))
+ var sanitizedQuery = SanitizeQuery(query);
+
+ if (!sanitizedQuery.Contains(QuerySplitCharacter, StringComparison.InvariantCultureIgnoreCase))
{
- queryKey = query;
+ queryKey = sanitizedQuery;
queryValueName = string.Empty;
return false;
}
- var querySplit = query.Split(QuerySplitCharacter);
+ var querySplit = sanitizedQuery.Split(QuerySplitCharacter);
queryKey = querySplit.First();
queryValueName = querySplit.Last();