mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	uri: do not encode userinfo fields
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 <marcandre.lureau@redhat.com>
This commit is contained in:
		
							
								
								
									
										16
									
								
								glib/guri.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								glib/guri.c
									
									
									
									
									
								
							| @@ -1634,33 +1634,19 @@ g_uri_build_with_user (GUriFlags    flags, | |||||||
|  |  | ||||||
|   if (user) |   if (user) | ||||||
|     { |     { | ||||||
|       userinfo = g_string_new (NULL); |       userinfo = g_string_new (user); | ||||||
|       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); |  | ||||||
|       if (password) |       if (password) | ||||||
|         { |         { | ||||||
|           g_string_append_c (userinfo, ':'); |           g_string_append_c (userinfo, ':'); | ||||||
|           if (flags & G_URI_FLAGS_ENCODED) |  | ||||||
|           g_string_append (userinfo, uri->password); |           g_string_append (userinfo, uri->password); | ||||||
|           else |  | ||||||
|             g_string_append_uri_escaped (userinfo, uri->password, |  | ||||||
|                                          PASSWORD_ALLOWED_CHARS, TRUE); |  | ||||||
|         } |         } | ||||||
|       if (auth_params) |       if (auth_params) | ||||||
|         { |         { | ||||||
|           g_string_append_c (userinfo, ';'); |           g_string_append_c (userinfo, ';'); | ||||||
|           if (flags & G_URI_FLAGS_ENCODED) |  | ||||||
|           g_string_append (userinfo, uri->auth_params); |           g_string_append (userinfo, uri->auth_params); | ||||||
|           else |  | ||||||
|             g_string_append_uri_escaped (userinfo, |  | ||||||
|                                          uri->auth_params, AUTH_PARAMS_ALLOWED_CHARS, TRUE); |  | ||||||
|         } |         } | ||||||
|       uri->userinfo = g_string_free (userinfo, FALSE); |       uri->userinfo = g_string_free (userinfo, FALSE); | ||||||
|     } |     } | ||||||
|   else |  | ||||||
|     uri->userinfo = NULL; |  | ||||||
|  |  | ||||||
|   return uri; |   return uri; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -987,6 +987,12 @@ test_uri_build (void) | |||||||
|   g_assert_cmpstr (g_uri_get_auth_params (uri), ==, "authparams"); |   g_assert_cmpstr (g_uri_get_auth_params (uri), ==, "authparams"); | ||||||
|   g_uri_unref (uri); |   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", |   uri = g_uri_build_with_user (G_URI_FLAGS_ENCODED, "scheme", "user%01", "password%02", | ||||||
|                                "authparams%03", "host", 1234, |                                "authparams%03", "host", 1234, | ||||||
|                                "/path", "query", "fragment"); |                                "/path", "query", "fragment"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user