mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-07 18:06:15 +01:00
uri: add ENCODED_PATH & ENCODED_FRAGMENT flags
Add encoded flags, similar to what was done in commit 7bee36b4
("uri:
add G_FLAGS_ENCODED_QUERY").
SoupURI has manual handling of encoded path & fragment, but it can rely
on GUri decoding for the rest.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
a97fe4e863
commit
c9c349aeaa
12
glib/guri.c
12
glib/guri.c
@ -787,8 +787,9 @@ g_uri_split_internal (const gchar *uri_string,
|
||||
end = p + strcspn (p, "#");
|
||||
if (*end == '#')
|
||||
{
|
||||
if (!uri_decode (fragment, NULL, end + 1, strlen (end + 1), FALSE, flags,
|
||||
G_URI_ERROR_BAD_FRAGMENT, error))
|
||||
if (!uri_normalize (fragment, end + 1, strlen (end + 1),
|
||||
flags | (flags & G_URI_FLAGS_ENCODED_FRAGMENT ? G_URI_FLAGS_ENCODED : 0),
|
||||
G_URI_ERROR_BAD_FRAGMENT, error))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -803,7 +804,8 @@ g_uri_split_internal (const gchar *uri_string,
|
||||
end = question;
|
||||
}
|
||||
|
||||
if (!uri_normalize (path, p, end - p, flags,
|
||||
if (!uri_normalize (path, p, end - p,
|
||||
flags | (flags & G_URI_FLAGS_ENCODED_PATH ? G_URI_FLAGS_ENCODED : 0),
|
||||
G_URI_ERROR_BAD_PATH, error))
|
||||
goto fail;
|
||||
|
||||
@ -1404,7 +1406,7 @@ g_uri_join_internal (GUriFlags flags,
|
||||
g_string_append_printf (str, ":%d", port);
|
||||
}
|
||||
|
||||
if (encoded)
|
||||
if (encoded || flags & G_URI_FLAGS_ENCODED_PATH)
|
||||
g_string_append (str, path);
|
||||
else
|
||||
g_string_append_uri_escaped (str, path, PATH_ALLOWED_CHARS, TRUE);
|
||||
@ -1420,7 +1422,7 @@ g_uri_join_internal (GUriFlags flags,
|
||||
if (fragment)
|
||||
{
|
||||
g_string_append_c (str, '#');
|
||||
if (encoded)
|
||||
if (encoded || flags & G_URI_FLAGS_ENCODED_FRAGMENT)
|
||||
g_string_append (str, fragment);
|
||||
else
|
||||
g_string_append_uri_escaped (str, fragment, FRAGMENT_ALLOWED_CHARS, TRUE);
|
||||
|
@ -55,6 +55,9 @@ void g_uri_unref (GUri *uri);
|
||||
* should not do any encoding itself.
|
||||
* @G_URI_FLAGS_ENCODED_QUERY: Same as %G_URI_FLAGS_ENCODED, for the query
|
||||
* field only.
|
||||
* @G_URI_FLAGS_ENCODED_PATH: Same as %G_URI_FLAGS_ENCODED, for the path only.
|
||||
* @G_URI_FLAGS_ENCODED_FRAGMENT: Same as %G_URI_FLAGS_ENCODED, for the
|
||||
* fragment only.
|
||||
* @G_URI_FLAGS_NONE: No flags set.
|
||||
*
|
||||
* Flags that describe a URI.
|
||||
@ -75,6 +78,8 @@ typedef enum {
|
||||
G_URI_FLAGS_ENCODED = 1 << 3,
|
||||
G_URI_FLAGS_NON_DNS = 1 << 4,
|
||||
G_URI_FLAGS_ENCODED_QUERY = 1 << 5,
|
||||
G_URI_FLAGS_ENCODED_PATH = 1 << 6,
|
||||
G_URI_FLAGS_ENCODED_FRAGMENT = 1 << 7,
|
||||
} GUriFlags;
|
||||
|
||||
GLIB_AVAILABLE_IN_2_66
|
||||
|
@ -1115,6 +1115,34 @@ test_uri_split (void)
|
||||
g_free (host);
|
||||
g_free (query);
|
||||
|
||||
g_uri_split ("http://h%01st/%C3%89t%C3%A9%2Bhiver",
|
||||
G_URI_FLAGS_ENCODED_PATH,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&path,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpstr (path, ==, "/%C3%89t%C3%A9%2Bhiver");
|
||||
g_free (path);
|
||||
|
||||
g_uri_split ("http://h%01st/path#%C3%89t%C3%A9%2Bhiver",
|
||||
G_URI_FLAGS_ENCODED_FRAGMENT,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&fragment,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpstr (fragment, ==, "%C3%89t%C3%A9%2Bhiver");
|
||||
g_free (fragment);
|
||||
|
||||
g_uri_split_with_user ("scheme://user:pass;auth@host:1234/path?query#fragment",
|
||||
G_URI_FLAGS_HAS_AUTH_PARAMS|G_URI_FLAGS_HAS_PASSWORD,
|
||||
NULL,
|
||||
|
Loading…
Reference in New Issue
Block a user