mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-13 04:46:15 +01:00
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>
This commit is contained in:
parent
b0f9af0e1d
commit
4c20ea477c
@ -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);
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user