Repository: microsoft/PowerToys
File: src/modules/launcher/Wox.Plugin/Common/DefaultBrowserInfo.cs (C#)

Code before:
                            .Replace("URL", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("HTML", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("Document", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("Web", null, StringComparison.OrdinalIgnoreCase)
                            .TrimEnd();
                    }

                    Name = appName;

                    string commandPattern = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\shell\open\command", null);

                    if (string.IsNullOrEmpty(commandPattern))
                    {
                        throw new ArgumentOutOfRangeException(
                            nameof(commandPattern),
                            "Default browser program command is not specified.");
                    }

                    if (commandPattern.StartsWith('@'))
                    {
                        commandPattern = GetIndirectString(commandPattern);
                    }

                    // workaround for firefox installed through Microsoft store
                    const string FirefoxExecutableName = "firefox.exe";
                    if (commandPattern.Contains(FirefoxExecutableName) && commandPattern.Contains(@"C:\Program Files\WindowsApps\") && (!commandPattern.StartsWith('\"')))
                    {
                        var pathEndIndex = commandPattern.IndexOf(FirefoxExecutableName, StringComparison.Ordinal) + FirefoxExecutableName.Length + 1;
                        commandPattern = commandPattern.Insert(0, "\"");
                        commandPattern = commandPattern.Insert(pathEndIndex, "\"");
                    }

                    if (commandPattern.StartsWith('\"'))
                    {
                        var endQuoteIndex = commandPattern.IndexOf('\"', 1);
                        if (endQuoteIndex != -1)
                        {
                            Path = commandPattern.Substring(1, endQuoteIndex - 1);
                            ArgumentsPattern = commandPattern.Substring(endQuoteIndex + 1).Trim();
                        }
                    }
                    else
                    {
                        var spaceIndex = commandPattern.IndexOf(' ');
                        if (spaceIndex != -1)
                        {
                            Path = commandPattern.Substring(0, spaceIndex);
                            ArgumentsPattern = commandPattern.Substring(spaceIndex + 1).Trim();
                        }
                    }


Review comment (suggestion):
Users might have this on another drive that might not be `C:\`.

Code after:
                            .Replace("URL", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("HTML", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("Document", null, StringComparison.OrdinalIgnoreCase)
                            .Replace("Web", null, StringComparison.OrdinalIgnoreCase)
                            .TrimEnd();
                    }

                    Name = appName;

                    string commandPattern = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\shell\open\command", null);

                    if (string.IsNullOrEmpty(commandPattern))
                    {
                        throw new ArgumentOutOfRangeException(
                            nameof(commandPattern),
                            "Default browser program command is not specified.");
                    }

                    if (commandPattern.StartsWith('@'))
                    {
                        commandPattern = GetIndirectString(commandPattern);
                    }

                    // HACK: for firefox installed through Microsoft store
                    // When installed through Microsoft Firefox the commandPattern does not have
                    // quotes for the path. As the Program Files does have a space
                    // the extracted path would be invalid, here we add the quotes to fix it
                    const string FirefoxExecutableName = "firefox.exe";
                    if (commandPattern.Contains(FirefoxExecutableName) && commandPattern.Contains(@"\WindowsApps\") && (!commandPattern.StartsWith('\"')))
                    {
                        var pathEndIndex = commandPattern.IndexOf(FirefoxExecutableName, StringComparison.Ordinal) + FirefoxExecutableName.Length;
                        commandPattern = commandPattern.Insert(pathEndIndex, "\"");
                        commandPattern = commandPattern.Insert(0, "\"");
                    }

                    if (commandPattern.StartsWith('\"'))
                    {
                        var endQuoteIndex = commandPattern.IndexOf('\"', 1);
                        if (endQuoteIndex != -1)
                        {
                            Path = commandPattern.Substring(1, endQuoteIndex - 1);
                            ArgumentsPattern = commandPattern.Substring(endQuoteIndex + 1).Trim();
                        }
                    }
                    else
                    {
                        var spaceIndex = commandPattern.IndexOf(' ');
                        if (spaceIndex != -1)
                        {
                            Path = commandPattern.Substring(0, spaceIndex);
                            ArgumentsPattern = commandPattern.Substring(spaceIndex + 1).Trim();