From b0f9af0e1d318ed6ecbeeb3734a1a6d2b6f082e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 30 Jul 2020 22:47:55 +0400 Subject: [PATCH] uri: do not encode userinfo fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit g_uri_build_with_user() builds a userinfo, but it shouldn't encode it itself, but let the user flags declare what's there. Otherwise, to_string() code paths may encode a second time. Signed-off-by: Marc-André Lureau --- glib/guri.c | 20 +++----------------- glib/tests/uri.c | 6 ++++++ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/glib/guri.c b/glib/guri.c index cffed414c..6d344b388 100644 --- a/glib/guri.c +++ b/glib/guri.c @@ -1634,33 +1634,19 @@ g_uri_build_with_user (GUriFlags flags, if (user) { - userinfo = g_string_new (NULL); - if (flags & G_URI_FLAGS_ENCODED) - g_string_append (userinfo, uri->user); - else - g_string_append_uri_escaped (userinfo, uri->user, USER_ALLOWED_CHARS, TRUE); + userinfo = g_string_new (user); if (password) { g_string_append_c (userinfo, ':'); - if (flags & G_URI_FLAGS_ENCODED) - g_string_append (userinfo, uri->password); - else - g_string_append_uri_escaped (userinfo, uri->password, - PASSWORD_ALLOWED_CHARS, TRUE); + g_string_append (userinfo, uri->password); } if (auth_params) { g_string_append_c (userinfo, ';'); - if (flags & G_URI_FLAGS_ENCODED) - g_string_append (userinfo, uri->auth_params); - else - g_string_append_uri_escaped (userinfo, - uri->auth_params, AUTH_PARAMS_ALLOWED_CHARS, TRUE); + g_string_append (userinfo, uri->auth_params); } uri->userinfo = g_string_free (userinfo, FALSE); } - else - uri->userinfo = NULL; return uri; } diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 83279747a..90053d783 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -987,6 +987,12 @@ test_uri_build (void) g_assert_cmpstr (g_uri_get_auth_params (uri), ==, "authparams"); g_uri_unref (uri); + uri = g_uri_build_with_user (G_URI_FLAGS_NONE, "scheme", "user\001", "password\002", + "authparams\003", "host", 1234, + "/path", "query", "fragment"); + g_assert_cmpstr (g_uri_get_userinfo (uri), ==, "user\001:password\002;authparams\003"); + g_uri_unref (uri); + uri = g_uri_build_with_user (G_URI_FLAGS_ENCODED, "scheme", "user%01", "password%02", "authparams%03", "host", 1234, "/path", "query", "fragment");