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>
This commit is contained in:
Marc-André Lureau 2020-07-30 19:54:49 +04:00
parent c354c404c6
commit ef173e2e75
2 changed files with 15 additions and 7 deletions

View File

@ -1328,6 +1328,7 @@ g_uri_resolve_relative (const gchar *base_uri_string,
static gchar * static gchar *
g_uri_join_internal (GUriFlags flags, g_uri_join_internal (GUriFlags flags,
const gchar *scheme, const gchar *scheme,
gboolean userinfo,
const gchar *user, const gchar *user,
const gchar *password, const gchar *password,
const gchar *auth_params, const gchar *auth_params,
@ -1353,11 +1354,14 @@ g_uri_join_internal (GUriFlags flags,
g_string_append (str, user); g_string_append (str, user);
else else
{ {
/* Encode ':' and ';' regardless of whether we have a if (userinfo)
* password or auth params, since it may be parsed later g_string_append_uri_escaped (str, user, USERINFO_ALLOWED_CHARS, TRUE);
* under the assumption that it does. else
*/ /* Encode ':' and ';' regardless of whether we have a
g_string_append_uri_escaped (str, user, USER_ALLOWED_CHARS, TRUE); * 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) if (password)
@ -1467,7 +1471,7 @@ g_uri_join (GUriFlags flags,
return g_uri_join_internal (flags, return g_uri_join_internal (flags,
scheme, scheme,
userinfo, NULL, NULL, TRUE, userinfo, NULL, NULL,
host, host,
port, port,
path, path,
@ -1519,7 +1523,7 @@ g_uri_join_with_user (GUriFlags flags,
return g_uri_join_internal (flags, return g_uri_join_internal (flags,
scheme, scheme,
user, password, auth_params, FALSE, user, password, auth_params,
host, host,
port, port,
path, path,

View File

@ -1403,6 +1403,10 @@ test_uri_join (void)
{ {
gchar *uri = NULL; 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", uri = g_uri_join_with_user (G_URI_FLAGS_NONE, "scheme", "user\001", "pass\002", "authparams\003",
"host", 9876, "/path", "query", "fragment"); "host", 9876, "/path", "query", "fragment");
g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@host:9876/path?query#fragment"); g_assert_cmpstr (uri, ==, "scheme://user%01:pass%02;authparams%03@host:9876/path?query#fragment");