mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
guri: Don’t fail g_uri_is_valid() if URI is missing a hostname
According to my reading of https://tools.ietf.org/html/rfc3986#section-4, the only requirement for a URI to be ‘absolute’ (actually, not a relative reference) is for the scheme to be specified. A hostname doesn’t have to be specified: see any of the options in the `hier-part` production in https://tools.ietf.org/html/rfc3986#appendix-A which don’t include `authority`. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
b5c59cc3fc
commit
943b1e45ab
20
glib/guri.c
20
glib/guri.c
@ -1101,10 +1101,28 @@ g_uri_is_valid (const gchar *uri_string,
|
||||
GUriFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
gchar *my_scheme = NULL;
|
||||
|
||||
g_return_val_if_fail (uri_string != NULL, FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
return g_uri_split_network (uri_string, flags, NULL, NULL, NULL, error);
|
||||
if (!g_uri_split_internal (uri_string, flags,
|
||||
&my_scheme, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
if (!my_scheme)
|
||||
{
|
||||
g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_SCHEME,
|
||||
_("URI ‘%s’ is not an absolute URI"),
|
||||
uri_string);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free (my_scheme);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1352,6 +1352,8 @@ test_uri_is_valid (void)
|
||||
g_assert_false (g_uri_is_valid ("http://host:6553l", G_URI_FLAGS_NONE, &error));
|
||||
g_assert_error (error, G_URI_ERROR, G_URI_ERROR_BAD_PORT);
|
||||
g_clear_error (&error);
|
||||
|
||||
g_assert_true (g_uri_is_valid ("data:,Hello", G_URI_FLAGS_NONE, &error));
|
||||
}
|
||||
|
||||
static const struct
|
||||
|
Loading…
Reference in New Issue
Block a user