mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-28 08:26:14 +01:00
Merge branch 'uri-encoded-parts' into 'master'
uri: add ENCODED_PATH & ENCODED_FRAGMENT flags See merge request GNOME/glib!1595
This commit is contained in:
commit
48ad40aca3
10
glib/guri.c
10
glib/guri.c
@ -787,7 +787,8 @@ g_uri_split_internal (const gchar *uri_string,
|
|||||||
end = p + strcspn (p, "#");
|
end = p + strcspn (p, "#");
|
||||||
if (*end == '#')
|
if (*end == '#')
|
||||||
{
|
{
|
||||||
if (!uri_decode (fragment, NULL, end + 1, strlen (end + 1), FALSE, flags,
|
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))
|
G_URI_ERROR_BAD_FRAGMENT, error))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -803,7 +804,8 @@ g_uri_split_internal (const gchar *uri_string,
|
|||||||
end = question;
|
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))
|
G_URI_ERROR_BAD_PATH, error))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@ -1404,7 +1406,7 @@ g_uri_join_internal (GUriFlags flags,
|
|||||||
g_string_append_printf (str, ":%d", port);
|
g_string_append_printf (str, ":%d", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoded)
|
if (encoded || flags & G_URI_FLAGS_ENCODED_PATH)
|
||||||
g_string_append (str, path);
|
g_string_append (str, path);
|
||||||
else
|
else
|
||||||
g_string_append_uri_escaped (str, path, PATH_ALLOWED_CHARS, TRUE);
|
g_string_append_uri_escaped (str, path, PATH_ALLOWED_CHARS, TRUE);
|
||||||
@ -1420,7 +1422,7 @@ g_uri_join_internal (GUriFlags flags,
|
|||||||
if (fragment)
|
if (fragment)
|
||||||
{
|
{
|
||||||
g_string_append_c (str, '#');
|
g_string_append_c (str, '#');
|
||||||
if (encoded)
|
if (encoded || flags & G_URI_FLAGS_ENCODED_FRAGMENT)
|
||||||
g_string_append (str, fragment);
|
g_string_append (str, fragment);
|
||||||
else
|
else
|
||||||
g_string_append_uri_escaped (str, fragment, FRAGMENT_ALLOWED_CHARS, TRUE);
|
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.
|
* should not do any encoding itself.
|
||||||
* @G_URI_FLAGS_ENCODED_QUERY: Same as %G_URI_FLAGS_ENCODED, for the query
|
* @G_URI_FLAGS_ENCODED_QUERY: Same as %G_URI_FLAGS_ENCODED, for the query
|
||||||
* field only.
|
* 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.
|
* @G_URI_FLAGS_NONE: No flags set.
|
||||||
*
|
*
|
||||||
* Flags that describe a URI.
|
* Flags that describe a URI.
|
||||||
@ -75,6 +78,8 @@ typedef enum {
|
|||||||
G_URI_FLAGS_ENCODED = 1 << 3,
|
G_URI_FLAGS_ENCODED = 1 << 3,
|
||||||
G_URI_FLAGS_NON_DNS = 1 << 4,
|
G_URI_FLAGS_NON_DNS = 1 << 4,
|
||||||
G_URI_FLAGS_ENCODED_QUERY = 1 << 5,
|
G_URI_FLAGS_ENCODED_QUERY = 1 << 5,
|
||||||
|
G_URI_FLAGS_ENCODED_PATH = 1 << 6,
|
||||||
|
G_URI_FLAGS_ENCODED_FRAGMENT = 1 << 7,
|
||||||
} GUriFlags;
|
} GUriFlags;
|
||||||
|
|
||||||
GLIB_AVAILABLE_IN_2_66
|
GLIB_AVAILABLE_IN_2_66
|
||||||
|
@ -1115,6 +1115,34 @@ test_uri_split (void)
|
|||||||
g_free (host);
|
g_free (host);
|
||||||
g_free (query);
|
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_split_with_user ("scheme://user:pass;auth@host:1234/path?query#fragment",
|
||||||
G_URI_FLAGS_HAS_AUTH_PARAMS|G_URI_FLAGS_HAS_PASSWORD,
|
G_URI_FLAGS_HAS_AUTH_PARAMS|G_URI_FLAGS_HAS_PASSWORD,
|
||||||
NULL,
|
NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user