mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Merge branch 'file-uri-cleanup' into 'main'
glocalvfs: Remove unnecessary and buggy code See merge request GNOME/glib!3776
This commit is contained in:
@@ -94,32 +94,9 @@ g_local_vfs_get_file_for_uri (GVfs *vfs,
|
||||
{
|
||||
char *path;
|
||||
GFile *file;
|
||||
char *stripped_uri, *hash, *question_mark;
|
||||
|
||||
/* As per https://url.spec.whatwg.org/#file-state, file: URIs can contain
|
||||
* query and fragment sections. We ignore them in order to get only the file
|
||||
* path. Compliance to this part of the WhatWG spec doesn’t necessarily mean
|
||||
* we comply with the entire spec. */
|
||||
if (strchr (uri, '#') != NULL)
|
||||
{
|
||||
stripped_uri = g_strdup (uri);
|
||||
hash = strchr (stripped_uri, '#');
|
||||
*hash = 0;
|
||||
}
|
||||
else if (strchr (uri, '?') != NULL)
|
||||
{
|
||||
stripped_uri = g_strdup (uri);
|
||||
question_mark = strchr (stripped_uri, '?');
|
||||
*question_mark = 0;
|
||||
}
|
||||
else
|
||||
stripped_uri = (char *)uri;
|
||||
|
||||
path = g_filename_from_uri (stripped_uri, NULL, NULL);
|
||||
path = g_filename_from_uri (uri, NULL, NULL);
|
||||
|
||||
if (stripped_uri != uri)
|
||||
g_free (stripped_uri);
|
||||
|
||||
if (path != NULL)
|
||||
file = _g_local_file_new (path);
|
||||
else
|
||||
|
@@ -3958,35 +3958,42 @@ test_enumerator_cancellation (void)
|
||||
}
|
||||
|
||||
static void
|
||||
test_from_uri_ignores_fragment (void)
|
||||
test_path_from_uri_helper (const gchar *uri,
|
||||
const gchar *expected_path)
|
||||
{
|
||||
GFile *file;
|
||||
gchar *path;
|
||||
file = g_file_new_for_uri ("file:///tmp/foo#bar");
|
||||
path = g_file_get_path (file);
|
||||
gchar *expected_platform_path;
|
||||
|
||||
expected_platform_path = g_strdup (expected_path);
|
||||
#ifdef G_OS_WIN32
|
||||
g_assert_cmpstr (path, ==, "\\tmp\\foo");
|
||||
#else
|
||||
g_assert_cmpstr (path, ==, "/tmp/foo");
|
||||
for (gchar *p = expected_platform_path; *p; p++)
|
||||
{
|
||||
if (*p == '/')
|
||||
*p = '\\';
|
||||
}
|
||||
#endif
|
||||
|
||||
file = g_file_new_for_uri (uri);
|
||||
path = g_file_get_path (file);
|
||||
g_assert_cmpstr (path, ==, expected_platform_path);
|
||||
g_free (path);
|
||||
g_object_unref (file);
|
||||
g_free (expected_platform_path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_from_uri_ignores_fragment (void)
|
||||
{
|
||||
test_path_from_uri_helper ("file:///tmp/foo#bar", "/tmp/foo");
|
||||
test_path_from_uri_helper ("file:///tmp/foo#bar?baz", "/tmp/foo");
|
||||
}
|
||||
|
||||
static void
|
||||
test_from_uri_ignores_query_string (void)
|
||||
{
|
||||
GFile *file;
|
||||
gchar *path;
|
||||
file = g_file_new_for_uri ("file:///tmp/foo?bar");
|
||||
path = g_file_get_path (file);
|
||||
#ifdef G_OS_WIN32
|
||||
g_assert_cmpstr (path, ==, "\\tmp\\foo");
|
||||
#else
|
||||
g_assert_cmpstr (path, ==, "/tmp/foo");
|
||||
#endif
|
||||
g_free (path);
|
||||
g_object_unref (file);
|
||||
test_path_from_uri_helper ("file:///tmp/foo?bar", "/tmp/foo");
|
||||
test_path_from_uri_helper ("file:///tmp/foo?bar#baz", "/tmp/foo");
|
||||
}
|
||||
|
||||
int
|
||||
|
Reference in New Issue
Block a user