[PATCH v2 1/2] winebrowser: Prefix an invalid URL with 'http://' before opening with a browser.

Brendan Shanks bshanks at codeweavers.com
Tue Nov 24 17:16:39 CST 2020


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 at codeweavers.com>
---

v2: Split invalid URL handling into separate function.

 programs/winebrowser/main.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/programs/winebrowser/main.c b/programs/winebrowser/main.c
index 9cd6812d032..c70457e50b3 100644
--- a/programs/winebrowser/main.c
+++ b/programs/winebrowser/main.c
@@ -184,6 +184,29 @@ static int open_mailto_url( const WCHAR *url )
     return launch_app( mailers, url );
 }
 
+static int open_invalid_url( const WCHAR *url )
+{
+    static const WCHAR httpW[] =
+        {'h','t','t','p',':','/','/',0};
+
+    WCHAR *url_prefixed;
+    int ret;
+
+    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 = open_http_url( url_prefixed );
+    HeapFree( GetProcessHeap(), 0, url_prefixed );
+    return ret;
+}
+
 /*****************************************************************************
  * DDE helper functions.
  */
@@ -448,8 +471,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_invalid_url(url);
         HeapFree(GetProcessHeap(), 0, ddeString);
         return ret;
     }
-- 
2.26.2




More information about the wine-devel mailing list