Repository: microsoft/terminal (language: cpp)

Issue:
Drag & drop in WSL should use single quotes
### Windows Terminal version

1.17.11461.0

### Windows build number

10.0.22621.1928

### Other Software

GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu) (inside WSL)

### Steps to reproduce

File drag & drop in WSL Bash:

```console
user@localhost~$ cat /mnt/c/Users/Admin/Desktop/$hello.txt
cat: /mnt/c/Users/Admin/Desktop/.txt: No such file or directory
user@localhost~$ cat "/mnt/c/Users/Admin/Desktop/$hello world.txt"
cat: '/mnt/c/Users/Admin/Desktop/ world.txt': No such file or directory
```

It does not work because `$hello` is recognized as a variable.

### Expected Behavior

```console
user@localhost~$ cat '/mnt/c/Users/Admin/Desktop/$hello.txt'
user@localhost~$ cat '/mnt/c/Users/Admin/Desktop/$hello world.txt'
```

or

```console
user@localhost~$ cat /mnt/c/Users/Admin/Desktop/\$hello.txt
user@localhost~$ cat /mnt/c/Users/Admin/Desktop/\$hello\ world.txt
```

### Actual Behavior

```console
user@localhost~$ cat /mnt/c/Users/Admin/Desktop/$hello.txt
cat: /mnt/c/Users/Admin/Desktop/.txt: No such file or directory
user@localhost~$ cat "/mnt/c/Users/Admin/Desktop/$hello world.txt"
cat: '/mnt/c/Users/Admin/Desktop/ world.txt': No such file or directory
```

：/


Discussion / hints:
> **Note**
> ## Walkthrough

FYI the code that does it is here: https://github.com/microsoft/terminal/blob/167819a8f407aac691da79e061af85a066ffcbc5/src/cascadia/TerminalControl/TermControl.cpp#L2800-L2804

The best course of action would be to use single quotes for WSL only, because cmd.exe doesn't get single quotes.
also x-ref #8109
Can someone help explain how I can locate the code that handles drag and drop for the terminal?
@Darkace01 I've linked the code the code that handles this in my comment above: https://github.com/microsoft/terminal/issues/15646#issuecomment-1622565414
If you set a breakpoint there, you should quickly find the call stack of a drag & drop.

Fix patch:
diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp
index 4406d364c92..4c59d027a52 100644
--- a/src/cascadia/TerminalControl/TermControl.cpp
+++ b/src/cascadia/TerminalControl/TermControl.cpp
@@ -2908,7 +2908,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
                     // However, it's likely that the control layer may need to
                     // know about the source anyways in the future, to support
                     // GH#3158
-                    if (_interactivity.ManglePathsForWsl())
+                    const auto isWSL = _interactivity.ManglePathsForWsl();
+
+                    if (isWSL)
                     {
                         std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');
 
@@ -2942,17 +2944,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
                         }
                     }
 
-                    const auto containsSpaces = std::find(fullPath.begin(),
-                                                          fullPath.end(),
-                                                          L' ') != fullPath.end();
+                    const auto quotesNeeded = isWSL || fullPath.find(L' ') != std::wstring::npos;
+                    const auto quotesChar = isWSL ? L'\'' : L'"';
 
-                    if (containsSpaces)
+                    // Append fullPath and also wrap it in quotes if needed
+                    if (quotesNeeded)
                     {
-                        fullPath.insert(0, L"\"");
-                        fullPath += L"\"";
+                        allPathsString.push_back(quotesChar);
+                    }
+                    allPathsString.append(fullPath);
+                    if (quotesNeeded)
+                    {
+                        allPathsString.push_back(quotesChar);
                     }
-
-                    allPathsString += fullPath;
                 }
 
                 _pasteTextWithBroadcast(winrt::hstring{ allPathsString });


Test patch: