[glib/glib-2-60: 3/4] gwinhttpvfs: Fall back to wrapped VFS if creating a HTTP file fails



commit 87c8168980f70fe6cc46bd7a8d88431813a34be0
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Jul 2 12:10:21 2019 +0100

    gwinhttpvfs: Fall back to wrapped VFS if creating a HTTP file fails
    
    If we fail to create a GWinhttpFile for a URI (for example, because it’s
    an invalid URI or is badly encoded), don’t just return NULL. Instead,
    fall back to the wrapped VFS which might be able to handle it instead.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Fixes: #1819

 gio/win32/gwinhttpvfs.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gio/win32/gwinhttpvfs.c b/gio/win32/gwinhttpvfs.c
index 038368f81..91d7fed9d 100644
--- a/gio/win32/gwinhttpvfs.c
+++ b/gio/win32/gwinhttpvfs.c
@@ -165,15 +165,25 @@ g_winhttp_vfs_get_file_for_uri (GVfs       *vfs,
 {
   GWinHttpVfs *winhttp_vfs = G_WINHTTP_VFS (vfs);
   int i;
+  GFile *ret = NULL;
 
   /* If it matches one of "our" schemes, handle it */
   for (i = 0; i < G_N_ELEMENTS (winhttp_uri_schemes); i++)
-    if (g_ascii_strncasecmp (uri, winhttp_uri_schemes[i], strlen (winhttp_uri_schemes[i])) == 0 &&
-        uri[strlen (winhttp_uri_schemes[i])] == ':')
-      return _g_winhttp_file_new (winhttp_vfs, uri);
+    {
+      if (g_ascii_strncasecmp (uri, winhttp_uri_schemes[i], strlen (winhttp_uri_schemes[i])) == 0 &&
+          uri[strlen (winhttp_uri_schemes[i])] == ':')
+        {
+          ret = _g_winhttp_file_new (winhttp_vfs, uri);
+        }
+    }
 
   /* For other URIs fallback to the wrapped GVfs */
-  return g_vfs_get_file_for_uri (winhttp_vfs->wrapped_vfs, uri);
+  if (ret == NULL)
+    ret = g_vfs_get_file_for_uri (winhttp_vfs->wrapped_vfs, uri);
+
+  g_assert (ret != NULL);
+
+  return g_steal_pointer (&ret);
 }
 
 static const gchar * const *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]