Fixes usage like 'winebrowser winehq.org' when xdg-open or macOS 'open' is used.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50094 Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- programs/winebrowser/main.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/programs/winebrowser/main.c b/programs/winebrowser/main.c index 9cd6812d032..7895afae842 100644 --- a/programs/winebrowser/main.c +++ b/programs/winebrowser/main.c @@ -118,7 +118,7 @@ static LSTATUS get_commands( HKEY key, const WCHAR *value, WCHAR *buffer, DWORD return res; }
-static int open_http_url( const WCHAR *url ) +static int open_http_url( const WCHAR *url, BOOL url_valid ) { #ifdef __APPLE__ static const WCHAR defaultbrowsers[] = @@ -136,9 +136,13 @@ static int open_http_url( const WCHAR *url ) #endif static const WCHAR browsersW[] = {'B','r','o','w','s','e','r','s',0}; + static const WCHAR httpW[] = + {'h','t','t','p',':','/','/',0};
WCHAR browsers[256]; + WCHAR *url_prefixed; HKEY key; + int ret; LONG r;
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */ @@ -150,7 +154,27 @@ static int open_http_url( const WCHAR *url ) if (r != ERROR_SUCCESS) memcpy( browsers, defaultbrowsers, sizeof(defaultbrowsers) );
- return launch_app( browsers, url ); + /* If url parsing failed, prefix url with 'http://'. Required by xdg-open and macOS open. */ + if (url_valid) + { + ret = launch_app( browsers, url ); + } + else + { + url_prefixed = HeapAlloc( GetProcessHeap(), 0, (ARRAY_SIZE(httpW) + strlenW( url )) * sizeof(WCHAR) ); + if (!url_prefixed) + { + WINE_ERR("Out of memory\n"); + return 1; + } + + strcpyW( url_prefixed, httpW ); + strcatW( url_prefixed, url ); + + ret = launch_app( browsers, url_prefixed ); + HeapFree( GetProcessHeap(), 0, url_prefixed ); + } + return ret; }
static int open_mailto_url( const WCHAR *url ) @@ -448,8 +472,8 @@ int __cdecl wmain(int argc, WCHAR *argv[])
hres = CreateUri(url, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME|Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri); if(FAILED(hres)) { - WINE_ERR("Failed to parse URL\n"); - ret = open_http_url(url); + WINE_ERR("Failed to parse URL %s, treating as HTTP\n", wine_dbgstr_w(url)); + ret = open_http_url(url, FALSE); HeapFree(GetProcessHeap(), 0, ddeString); return ret; } @@ -476,7 +500,7 @@ int __cdecl wmain(int argc, WCHAR *argv[]) ret = open_mailto_url(display_uri); else /* let the browser decide how to handle the given url */ - ret = open_http_url(display_uri); + ret = open_http_url(display_uri, TRUE);
SysFreeString(display_uri); return ret;