Repository: microsoft/terminal
File: src/cascadia/TerminalControl/TermControl.cpp (C++)

Code before:
                    // Join the paths with spaces
                    if (!allPaths.empty())
                    {
                        allPaths += L" ";
                    }

                    std::wstring fullPath{ item.Path() };

                    // Fix path for WSL
                    if (_settings.ProfileSource() == L"Windows.Terminal.Wsl")
                    {
                        // Use unix path separator
                        std::replace(fullPath.begin(), fullPath.end(), '\\', '/');

                        // remove colon and lowercase drive letter
                        if (fullPath.at(1) == ':')
                        {
                            fullPath.erase(1, 1);
                            fullPath.replace(0, 1, 1, std::towlower(fullPath.at(0)));
                            fullPath.insert(0, L"/mnt/");
                        }
                        // Remove \\wsl.localhost from the string (leaving the raw Linux filesystem path)
                        else if (fullPath.find(L"//wsl.localhost") != std::string::npos)
                        {
                            fullPath.erase(0, fullPath.find('/', fullPath.find('/', fullPath.find('/', fullPath.find('/') + 1) + 1) + 1));
                        }
                    }

                    const auto containsSpaces = std::find(fullPath.begin(),
                                                          fullPath.end(),
                                                          L' ') != fullPath.end();

                    if (containsSpaces)
                    {
                        fullPath.insert(0, L"\"");
                        fullPath += L"\"";
                    }

                    allPaths += fullPath;
                }

                _core.PasteText(winrt::hstring{ allPaths });
            }
        }
    }

    // Method Description:
    // - Handle the DragOver event. We'll signal that the drag operation we
    //   support is the "copy" operation, and we'll also customize the
    //   appearance of the drag-drop UI, by removing the preview and setting a
    //   custom caption. For more information, see

Review comment (suggestion):
```suggestion
                        static constexpr std::wstring_view wslPathPrefix{L"//wsl.localhost/"};
                        std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');

                        if (fullPath.size() >= 2 && fullPath.at(1) == L':')
                        {
                            // C:/foo/bar -> Cc/foo/bar
                            fullPath.at(1) = til::tolower_ascii(fullPath.at(0));
                            // Cc/foo/bar -> /mnt/c/foo/bar
                            fullPath.replace(0, 1, L"/mnt/");
                        }
                        else if (til::starts_with(fullPath, wslPathPrefix))
                        {
                            if (const auto idx = fullPath.find(L'/', wslPathPrefix.size()); idx != std::wstring::npos)
                            {
                                // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
                                fullPath.erase(0, idx);
                            }
                            else
                            {
                                // //wsl.localhost/Ubuntu-18.04 -> /
                                fullPath = L"/";
                            }
                        }
```

The advantages are:
* It's less code (well more whitespace, but less transitive code)
* It handles the corner case of passing the WSL root directory properly

Code after:
                    // Join the paths with spaces
                    if (!allPaths.empty())
                    {
                        allPaths += L" ";
                    }

                    std::wstring fullPath{ item.Path() };

                    // Fix path for WSL
                    if (_settings.ProfileSource() == L"Windows.Terminal.Wsl")
                    {
                        std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');

                        if (fullPath.size() >= 2 && fullPath.at(1) == L':')
                        {
                            // C:/foo/bar -> Cc/foo/bar
                            fullPath.at(1) = til::tolower_ascii(fullPath.at(0));
                            // Cc/foo/bar -> /mnt/c/foo/bar
                            fullPath.replace(0, 1, L"/mnt/");
                        }
                        else
                        {
                            static constexpr std::wstring_view wslPathPrefixes[] = { L"//wsl.localhost/", L"//wsl$/" };
                            for (auto prefix : wslPathPrefixes)
                            {
                                if (til::starts_with(fullPath, prefix))
                                {
                                    if (const auto idx = fullPath.find(L'/', prefix.size()); idx != std::wstring::npos)
                                    {
                                        // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
                                        fullPath.erase(0, idx);
                                    }
                                    else
                                    {
                                        // //wsl.localhost/Ubuntu-18.04 -> /
                                        fullPath = L"/";
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    const auto containsSpaces = std::find(fullPath.begin(),
                                                          fullPath.end(),
                                                          L' ') != fullPath.end();

                    if (containsSpaces)
                    {
                        fullPath.insert(0, L"\"");
                        fullPath += L"\"";