[glib: 6/15] guri: Add G_URI_HIDE_QUERY




commit f873b88f8966a9b476f6b87145a04cd870e30ad3
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Aug 6 14:02:21 2020 +0100

    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>

 glib/guri.c      | 5 +++--
 glib/guri.h      | 4 +++-
 glib/tests/uri.c | 3 +++
 3 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index 9f575f8b1..c7edf137b 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -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);
 }
 
diff --git a/glib/guri.h b/glib/guri.h
index 832bf5d3d..a85fd9e4b 100644
--- a/glib/guri.h
+++ b/glib/guri.h
@@ -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
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 71e3150ff..85d2eb19d 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -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);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]