mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 22:46:15 +01:00
uri: allow to join a partial URI, without scheme
Fixes: #2166 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
bb1df0e515
commit
0ba7ebfda9
14
glib/guri.c
14
glib/guri.c
@ -1348,10 +1348,12 @@ g_uri_join_internal (GUriFlags flags,
|
|||||||
GString *str;
|
GString *str;
|
||||||
|
|
||||||
str = g_string_new (scheme);
|
str = g_string_new (scheme);
|
||||||
|
if (scheme)
|
||||||
g_string_append_c (str, ':');
|
g_string_append_c (str, ':');
|
||||||
|
|
||||||
if (host)
|
if (host)
|
||||||
{
|
{
|
||||||
|
if (scheme)
|
||||||
g_string_append (str, "//");
|
g_string_append (str, "//");
|
||||||
|
|
||||||
if (user)
|
if (user)
|
||||||
@ -1442,7 +1444,7 @@ g_uri_join_internal (GUriFlags flags,
|
|||||||
/**
|
/**
|
||||||
* g_uri_join:
|
* g_uri_join:
|
||||||
* @flags: flags describing how to build the URI string
|
* @flags: flags describing how to build the URI string
|
||||||
* @scheme: the URI scheme
|
* @scheme: (nullable): the URI scheme, or %NULL
|
||||||
* @userinfo: (nullable): the userinfo component, or %NULL
|
* @userinfo: (nullable): the userinfo component, or %NULL
|
||||||
* @host: (nullable): the host component, or %NULL
|
* @host: (nullable): the host component, or %NULL
|
||||||
* @port: the port, or -1
|
* @port: the port, or -1
|
||||||
@ -1451,8 +1453,7 @@ g_uri_join_internal (GUriFlags flags,
|
|||||||
* @fragment: (nullable): the fragment, or %NULL
|
* @fragment: (nullable): the fragment, or %NULL
|
||||||
*
|
*
|
||||||
* Joins the given components together according to @flags to create
|
* Joins the given components together according to @flags to create
|
||||||
* an absolute URI string. At least @scheme must be specified, and
|
* an absolute URI string. @path may not be %NULL (though it may be "").
|
||||||
* @path may not be %NULL (though it may be "").
|
|
||||||
*
|
*
|
||||||
* See also g_uri_join_with_user(), which allows specifying the
|
* See also g_uri_join_with_user(), which allows specifying the
|
||||||
* components of the "userinfo" separately.
|
* components of the "userinfo" separately.
|
||||||
@ -1471,7 +1472,6 @@ g_uri_join (GUriFlags flags,
|
|||||||
const gchar *query,
|
const gchar *query,
|
||||||
const gchar *fragment)
|
const gchar *fragment)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (scheme != NULL, NULL);
|
|
||||||
g_return_val_if_fail (port >= -1 && port <= 65535, NULL);
|
g_return_val_if_fail (port >= -1 && port <= 65535, NULL);
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
@ -1488,7 +1488,7 @@ g_uri_join (GUriFlags flags,
|
|||||||
/**
|
/**
|
||||||
* g_uri_join_with_user:
|
* g_uri_join_with_user:
|
||||||
* @flags: flags describing how to build the URI string
|
* @flags: flags describing how to build the URI string
|
||||||
* @scheme: the URI scheme
|
* @scheme: (nullable): the URI scheme, or %NULL
|
||||||
* @user: (nullable): the user component of the userinfo, or %NULL
|
* @user: (nullable): the user component of the userinfo, or %NULL
|
||||||
* @password: (nullable): the password component of the userinfo, or
|
* @password: (nullable): the password component of the userinfo, or
|
||||||
* %NULL
|
* %NULL
|
||||||
@ -1501,8 +1501,7 @@ g_uri_join (GUriFlags flags,
|
|||||||
* @fragment: (nullable): the fragment, or %NULL
|
* @fragment: (nullable): the fragment, or %NULL
|
||||||
*
|
*
|
||||||
* Joins the given components together according to @flags to create
|
* Joins the given components together according to @flags to create
|
||||||
* an absolute URI string. At least @scheme must be specified, and
|
* an absolute URI string. @path may not be %NULL (though it may be "").
|
||||||
* @path may not be %NULL (though it may be "").
|
|
||||||
*
|
*
|
||||||
* In constrast to g_uri_join(), this allows specifying the components
|
* In constrast to g_uri_join(), this allows specifying the components
|
||||||
* of the "userinfo" separately.
|
* of the "userinfo" separately.
|
||||||
@ -1523,7 +1522,6 @@ g_uri_join_with_user (GUriFlags flags,
|
|||||||
const gchar *query,
|
const gchar *query,
|
||||||
const gchar *fragment)
|
const gchar *fragment)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (scheme != NULL, NULL);
|
|
||||||
g_return_val_if_fail (port >= -1 && port <= 65535, NULL);
|
g_return_val_if_fail (port >= -1 && port <= 65535, NULL);
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
|
@ -1523,6 +1523,10 @@ test_uri_join (void)
|
|||||||
g_assert_cmpstr (uri, ==, "foo://some:user%40info@bar");
|
g_assert_cmpstr (uri, ==, "foo://some:user%40info@bar");
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
|
|
||||||
|
uri = g_uri_join (G_URI_FLAGS_NONE, NULL, NULL, NULL, -1, "/foo", "abc", NULL);
|
||||||
|
g_assert_cmpstr (uri, ==, "/foo?abc");
|
||||||
|
g_free (uri);
|
||||||
|
|
||||||
uri = g_uri_join_with_user (G_URI_FLAGS_NONE, "scheme", "user\001", "pass\002", "authparams\003",
|
uri = g_uri_join_with_user (G_URI_FLAGS_NONE, "scheme", "user\001", "pass\002", "authparams\003",
|
||||||
"host", 9876, "/path", "query", "fragment");
|
"host", 9876, "/path", "query", "fragment");
|
||||||
g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@host:9876/path?query#fragment");
|
g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@host:9876/path?query#fragment");
|
||||||
|
Loading…
Reference in New Issue
Block a user