gfile: Strip query sections from file: URIs

According to https://url.spec.whatwg.org/#file-state
a file URI can have a fragment and query string, so just ignore them
and don't raise an invalid URI error.

Fixes: #3050
This commit is contained in:
Lukáš Tyrychtr
2023-07-14 13:02:28 +02:00
committed by Philip Withnall
parent 215a6ed80c
commit b504cc0841
5 changed files with 107 additions and 14 deletions

View File

@@ -94,14 +94,24 @@ g_local_vfs_get_file_for_uri (GVfs *vfs,
{
char *path;
GFile *file;
char *stripped_uri, *hash;
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 doesnt 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;