[glib: 2/5] uri: always add G_URI_FLAGS_HAS_PASSWORD with build_with_user()




commit 4c20ea477ce0da433a350d9e2c1ef34c9a1337a3
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Thu Jul 30 23:10:32 2020 +0400

    uri: always add G_URI_FLAGS_HAS_PASSWORD with build_with_user()
    
    Otherwise, the to_string() encoding will not be reversible. Furthermore,
    if no distinction is needed in the first place, g_uri_build() with
    userinfo should be used instead.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 glib/guri.c      | 7 +++++--
 glib/tests/uri.c | 6 +++---
 2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index 6d344b388..d3f4238a4 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -1589,7 +1589,10 @@ g_uri_build (GUriFlags    flags,
  * @query: (nullable): the query component, or %NULL
  * @fragment: (nullable): the fragment, or %NULL
  *
- * Creates a new #GUri from the given components according to @flags.
+ * Creates a new #GUri from the given components according to @flags
+ * (%G_URI_FLAGS_HAS_PASSWORD is added unconditionally). The @flags must be
+ * coherent with the passed values, in particular use `%`-encoded values with
+ * %G_URI_FLAGS_ENCODED.
 
  * In constrast to g_uri_build(), this allows specifying the components
  * of the "userinfo" field separately. Note that @user must be non-%NULL
@@ -1621,7 +1624,7 @@ g_uri_build_with_user (GUriFlags    flags,
   g_return_val_if_fail (path != NULL, NULL);
 
   uri = g_atomic_rc_box_new0 (GUri);
-  uri->flags = flags;
+  uri->flags = flags | G_URI_FLAGS_HAS_PASSWORD;
   uri->scheme = g_ascii_strdown (scheme, -1);
   uri->user = g_strdup (user);
   uri->password = g_strdup (password);
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 90053d783..8b83dd55a 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -921,13 +921,13 @@ test_uri_to_string (void)
   uri = g_uri_build_with_user (G_URI_FLAGS_NONE, "scheme", "user", "pass", "auth", "host", 1234,
                                "/path", "query", "fragment");
   tostring = g_uri_to_string (uri);
-  g_assert_cmpstr (tostring, ==, "scheme://user%3Apass%3Bauth@host:1234/path?query#fragment");
+  g_assert_cmpstr (tostring, ==, "scheme://user:pass;auth@host:1234/path?query#fragment");
   g_free (tostring);
   tostring = g_uri_to_string_partial (uri, G_URI_HIDE_USERINFO);
   g_assert_cmpstr (tostring, ==, "scheme://host:1234/path?query#fragment");
   g_free (tostring);
   tostring = g_uri_to_string_partial (uri, G_URI_HIDE_FRAGMENT);
-  g_assert_cmpstr (tostring, ==, "scheme://user%3Apass%3Bauth@host:1234/path?query");
+  g_assert_cmpstr (tostring, ==, "scheme://user:pass;auth@host:1234/path?query");
   g_free (tostring);
   g_uri_unref (uri);
 
@@ -974,7 +974,7 @@ test_uri_build (void)
                                "authparams", "host", 1234,
                                "/path", "query", "fragment");
 
-  g_assert_cmpint (g_uri_get_flags (uri), ==, G_URI_FLAGS_NON_DNS);
+  g_assert_cmpint (g_uri_get_flags (uri), ==, G_URI_FLAGS_NON_DNS | G_URI_FLAGS_HAS_PASSWORD);
   g_assert_cmpstr (g_uri_get_scheme (uri), ==, "scheme");
   g_assert_cmpstr (g_uri_get_userinfo (uri), ==, "user:password;authparams");
   g_assert_cmpstr (g_uri_get_host (uri), ==, "host");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]