WSL - Can't open URL with equal sign - proposed patch/fix included
Trying to open a URL with a query parameter (equal sign) in WSL causes Windows to open the Documents window.
xdg-open "https://google.com/?help"
- works, opens URL in browser
xdg-open "https://google.com/?help=me"
- Doesn't work, opens Windows Explorer to the Documents folder
xdg-open is called by git-credential-manager to do OAuth, where it passes URLs with several query parameters.
I changed my xdg-open script locally and was able to get this working... Change below.
The rundll32.exe call seems to open any URL format as-expected, so here I'm just trying to use that for URL-type arguments, or explorer.exe for everything else.
I haven't validated exit-codes from rundll32.exe, just assuming it has sane behavior there. Like I said, this seems to work fine for me locally
open_wsl()
{
local win_path
if has_url_scheme "$1"; then
win_path="$1"
rundll32.exe url.dll,FileProtocolHandler "${win_path}"
else
win_path="$(wslpath -aw "$1")"
[ $? -eq 0 ] || exit_failure_operation_failed
explorer.exe "${win_path}"
fi
if [ $? -eq 0 ]; then
exit_success
else
exit_failure_operation_failed
fi
}