[glib: 1/2] uri: allow to join a partial URI, without scheme
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] uri: allow to join a partial URI, without scheme
- Date: Wed, 5 Aug 2020 19:14:22 +0000 (UTC)
commit 0ba7ebfda993f6fd70fd2f387c1ab4e82dbc7519
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Wed Aug 5 22:29:42 2020 +0400
uri: allow to join a partial URI, without scheme
Fixes: #2166
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
glib/guri.c | 18 ++++++++----------
glib/tests/uri.c | 4 ++++
2 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index 2890d44e4..ed320ab3d 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -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);
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index ae651b0a3..982040888 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -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");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]