[glib: 4/5] uri: do not encode ':' and ';' from userinfo




commit ef173e2e7596a7793d85128c6e8b3ae00a2068b5
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Thu Jul 30 19:54:49 2020 +0400

    uri: do not encode ':' and ';' from userinfo
    
    The g_uri_join_internal() function was making a simplification that
    userinfo can be encoded with the same restricted character set as the
    user field alone, fix this by allowing the correct character set.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 glib/guri.c      | 18 +++++++++++-------
 glib/tests/uri.c |  4 ++++
 2 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index d3f4238a4..f5b9fd3fd 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -1328,6 +1328,7 @@ g_uri_resolve_relative (const gchar  *base_uri_string,
 static gchar *
 g_uri_join_internal (GUriFlags    flags,
                      const gchar *scheme,
+                     gboolean     userinfo,
                      const gchar *user,
                      const gchar *password,
                      const gchar *auth_params,
@@ -1353,11 +1354,14 @@ g_uri_join_internal (GUriFlags    flags,
             g_string_append (str, user);
           else
             {
-              /* Encode ':' and ';' regardless of whether we have a
-               * password or auth params, since it may be parsed later
-               * under the assumption that it does.
-               */
-              g_string_append_uri_escaped (str, user, USER_ALLOWED_CHARS, TRUE);
+              if (userinfo)
+                g_string_append_uri_escaped (str, user, USERINFO_ALLOWED_CHARS, TRUE);
+              else
+                /* Encode ':' and ';' regardless of whether we have a
+                 * password or auth params, since it may be parsed later
+                 * under the assumption that it does.
+                 */
+                g_string_append_uri_escaped (str, user, USER_ALLOWED_CHARS, TRUE);
             }
 
           if (password)
@@ -1467,7 +1471,7 @@ g_uri_join (GUriFlags    flags,
 
   return g_uri_join_internal (flags,
                               scheme,
-                              userinfo, NULL, NULL,
+                              TRUE, userinfo, NULL, NULL,
                               host,
                               port,
                               path,
@@ -1519,7 +1523,7 @@ g_uri_join_with_user (GUriFlags    flags,
 
   return g_uri_join_internal (flags,
                               scheme,
-                              user, password, auth_params,
+                              FALSE, user, password, auth_params,
                               host,
                               port,
                               path,
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 421a1284d..0392f034e 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -1403,6 +1403,10 @@ test_uri_join (void)
 {
   gchar *uri = NULL;
 
+  uri = g_uri_join (G_URI_FLAGS_NONE, "foo", "some:user@info", "bar", -1, "", NULL, NULL);
+  g_assert_cmpstr (uri, ==, "foo://some:user%40info@bar");
+  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]