Repository: electron/electron (language: cpp)

Issue:
[Bug]: setAsDefaultProtocolClient sets wrong command
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

16.0.7

### What operating system are you using?

Windows

### Operating System Version

Windows 10 Build 19043

### What arch are you using?

x64

### Last Known Working Electron version

13.1.2

### Expected Behavior

`app.setAsDefaultProtocolClient(protocol, process.execPath, [path.resolve(process.argv[1]), '--arg']);`
to work as expected.

### Actual Behavior

electron will put quotes around the entire list of arguments instead of each individually (if necessary), so the generated command is something like

"C:\example\node_modules\electron\dist\electron.exe" "c:\example --arg" "%1"

which then leads to an error "Unable to find Electron app at c:\example --args".

### Testcase Gist URL

!!! Please note that by the nature of setAsDefaultProtocolClient this testcase will make a systemwide setting!

https://gist.github.com/a1f2fdbe04624b6f7a6877a89581143c

### Additional Information

This was almost certainly introduced by the "fix" for https://github.com/electron/electron/issues/32141


Discussion / hints:
This sounds plausible, both the bug report and the triage work that you did to track down the likely problem.

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? [Electron Fiddle](https://www.electronjs.org/fiddle) is a great tool for making small testcases and publishing them as [gists](https://gist.github.com) that Electron maintainers can use.
Related to #31710 maybe? cc @bitdisaster 
> This sounds plausible, both the bug report and the triage work that you did to track down the likely problem.
> 
> Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? [Electron Fiddle](https://www.electronjs.org/fiddle) is a great tool for making small testcases and publishing them as [gists](https://gist.github.com) that Electron maintainers can use.

I added a testcase to the original post.
@ckerr repro was added

Fix patch:
diff --git a/shell/browser/browser_win.cc b/shell/browser/browser_win.cc
index 6cfc75f4a44ba..56a62ac32548f 100644
--- a/shell/browser/browser_win.cc
+++ b/shell/browser/browser_win.cc
@@ -67,7 +67,7 @@ bool GetProtocolLaunchPath(gin::Arguments* args, std::wstring* exe) {
   std::vector<std::wstring> launch_args;
   if (args->GetNext(&launch_args) && !launch_args.empty())
     *exe = base::StringPrintf(L"\"%ls\" \"%ls\" \"%%1\"", exe->c_str(),
-                              base::JoinString(launch_args, L" ").c_str());
+                              base::JoinString(launch_args, L"\"  \"").c_str());
   else
     *exe = base::StringPrintf(L"\"%ls\" \"%%1\"", exe->c_str());
   return true;


Test patch: