[PATCH] winebrowser: Ensure that a URL opened as HTTP begins with 'http://' or 'https://'.

Brendan Shanks bshanks at codeweavers.com
Tue Aug 11 16:09:01 CDT 2020


Fixes usage like 'winebrowser winehq.org' when xdg-open is used.

Signed-off-by: Brendan Shanks <bshanks at codeweavers.com>
---
 programs/winebrowser/main.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/programs/winebrowser/main.c b/programs/winebrowser/main.c
index 9cd6812d032..4b623dfac78 100644
--- a/programs/winebrowser/main.c
+++ b/programs/winebrowser/main.c
@@ -136,9 +136,15 @@ 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};
+    static const WCHAR httpsW[] =
+        {'h','t','t','p','s',':','/','/',0};
 
     WCHAR browsers[256];
+    WCHAR *url_prefixed;
     HKEY key;
+    int ret;
     LONG r;
 
     /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
@@ -150,7 +156,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 doesn't begin with 'http://' or 'https://', prefix it with 'http://'. Required by xdg-open. */
+    if (!strncmpiW( url, httpW, strlenW( httpW ) ) || !strncmpiW( url, httpsW , strlenW( httpsW ) ))
+    {
+        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 )
-- 
2.26.2




More information about the wine-devel mailing list