Merge branch 'guri-join-schemeless' into 'master'

uri: allow to join a partial URI, without scheme

Closes #2166

See merge request GNOME/glib!1606
This commit is contained in:
Sebastian Dröge 2020-08-05 19:14:21 +00:00
commit a2c8f6f719
2 changed files with 12 additions and 10 deletions

View File

@ -1348,11 +1348,13 @@ g_uri_join_internal (GUriFlags flags,
GString *str;
str = g_string_new (scheme);
g_string_append_c (str, ':');
if (scheme)
g_string_append_c (str, ':');
if (host)
{
g_string_append (str, "//");
if (scheme)
g_string_append (str, "//");
if (user)
{
@ -1442,7 +1444,7 @@ g_uri_join_internal (GUriFlags flags,
/**
* g_uri_join:
* @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
* @host: (nullable): the host component, or %NULL
* @port: the port, or -1
@ -1451,8 +1453,7 @@ g_uri_join_internal (GUriFlags flags,
* @fragment: (nullable): the fragment, or %NULL
*
* Joins the given components together according to @flags to create
* an absolute URI string. At least @scheme must be specified, and
* @path may not be %NULL (though it may be "").
* an absolute URI string. @path may not be %NULL (though it may be "").
*
* See also g_uri_join_with_user(), which allows specifying the
* components of the "userinfo" separately.
@ -1471,7 +1472,6 @@ g_uri_join (GUriFlags flags,
const gchar *query,
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 (path != NULL, NULL);
@ -1488,7 +1488,7 @@ g_uri_join (GUriFlags flags,
/**
* g_uri_join_with_user:
* @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
* @password: (nullable): the password component of the userinfo, or
* %NULL
@ -1501,8 +1501,7 @@ g_uri_join (GUriFlags flags,
* @fragment: (nullable): the fragment, or %NULL
*
* Joins the given components together according to @flags to create
* an absolute URI string. At least @scheme must be specified, and
* @path may not be %NULL (though it may be "").
* an absolute URI string. @path may not be %NULL (though it may be "").
*
* In constrast to g_uri_join(), this allows specifying the components
* of the "userinfo" separately.
@ -1523,7 +1522,6 @@ g_uri_join_with_user (GUriFlags flags,
const gchar *query,
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 (path != NULL, NULL);

View File

@ -1523,6 +1523,10 @@ test_uri_join (void)
g_assert_cmpstr (uri, ==, "foo://some:user%40info@bar");
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",
"host", 9876, "/path", "query", "fragment");
g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@host:9876/path?query#fragment");