guri: Add G_URI_HIDE_QUERY

Sometimes there are sensitive details in URI query components, so we
should provide the option for hiding them too.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-08-06 14:02:21 +01:00
parent ae6a0ef8b8
commit f873b88f89
3 changed files with 9 additions and 3 deletions

View File

@ -1775,6 +1775,7 @@ g_uri_to_string_partial (GUri *uri,
gboolean hide_user = (flags & G_URI_HIDE_USERINFO);
gboolean hide_password = (flags & (G_URI_HIDE_USERINFO | G_URI_HIDE_PASSWORD));
gboolean hide_auth_params = (flags & (G_URI_HIDE_USERINFO | G_URI_HIDE_AUTH_PARAMS));
gboolean hide_query = (flags & G_URI_HIDE_QUERY);
gboolean hide_fragment = (flags & G_URI_HIDE_FRAGMENT);
g_return_val_if_fail (uri != NULL, NULL);
@ -1789,7 +1790,7 @@ g_uri_to_string_partial (GUri *uri,
uri->host,
uri->port,
uri->path,
uri->query,
hide_query ? NULL : uri->query,
hide_fragment ? NULL : uri->fragment);
}
@ -1799,7 +1800,7 @@ g_uri_to_string_partial (GUri *uri,
uri->host,
uri->port,
uri->path,
uri->query,
hide_query ? NULL : uri->query,
hide_fragment ? NULL : uri->fragment);
}

View File

@ -184,6 +184,7 @@ GUri * g_uri_build_with_user (GUriFlags flags,
* @G_URI_HIDE_USERINFO: Hide the userinfo.
* @G_URI_HIDE_PASSWORD: Hide the password.
* @G_URI_HIDE_AUTH_PARAMS: Hide the auth_params.
* @G_URI_HIDE_QUERY: Hide the query.
* @G_URI_HIDE_FRAGMENT: Hide the fragment.
*
* Flags describing what parts of the URI to hide in
@ -199,7 +200,8 @@ typedef enum {
G_URI_HIDE_USERINFO = 1 << 0,
G_URI_HIDE_PASSWORD = 1 << 1,
G_URI_HIDE_AUTH_PARAMS = 1 << 2,
G_URI_HIDE_FRAGMENT = 1 << 3,
G_URI_HIDE_QUERY = 1 << 3,
G_URI_HIDE_FRAGMENT = 1 << 4,
} GUriHideFlags;
GLIB_AVAILABLE_IN_2_66

View File

@ -950,6 +950,9 @@ test_uri_to_string (void)
tostring = g_uri_to_string_partial (uri, G_URI_HIDE_AUTH_PARAMS);
g_assert_cmpstr (tostring, ==, "scheme://us%3Aer:pass@host:1234/path?query#fragment");
g_free (tostring);
tostring = g_uri_to_string_partial (uri, G_URI_HIDE_QUERY);
g_assert_cmpstr (tostring, ==, "scheme://us%3Aer:pass;auth@host:1234/path#fragment");
g_free (tostring);
g_uri_unref (uri);
}