[glib: 5/13] uri: change g_uri_is_valid() to check absolute URI




commit 82ad7853baacdc10f57279429cecedc35f862a41
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Tue Jul 28 15:42:33 2020 +0400

    uri: change g_uri_is_valid() to check absolute URI
    
    g_uri_is_valid() should check the given URI is valid following RFC-3986,
    and reject relative references.
    
    Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2169
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 glib/guri.c      | 19 ++++++++-----------
 glib/guri.h      |  2 +-
 glib/tests/uri.c |  4 +++-
 3 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index a4481204e..d20b2eacc 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -1039,32 +1039,29 @@ g_uri_split_network (const gchar  *uri_string,
 
 /**
  * g_uri_is_valid:
- * @uri_ref: a string containing a relative or absolute URI
- * @flags: flags for parsing @uri_ref
+ * @uri_string: a string containing an absolute URI
+ * @flags: flags for parsing @uri_string
  * @error: #GError for error reporting, or %NULL to ignore.
  *
- * Parses @uri_ref (which can be an absolute or relative URI)
- * according to @flags, to determine whether it is valid.
+ * Parses @uri_string according to @flags, to determine whether it is valid
+ * absolute URI.
  *
  * See g_uri_split(), and the definition of #GUriFlags, for more
  * information on the effect of @flags.
  *
- * Returns: %TRUE if @uri_ref parsed successfully, %FALSE on error.
+ * Returns: %TRUE if @uri_string parsed successfully, %FALSE on error.
  *
  * Since: 2.66
  */
 gboolean
-g_uri_is_valid (const gchar  *uri_ref,
+g_uri_is_valid (const gchar  *uri_string,
                 GUriFlags     flags,
                 GError      **error)
 {
-  g_return_val_if_fail (uri_ref != NULL, FALSE);
+  g_return_val_if_fail (uri_string != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  return g_uri_split_internal (uri_ref, flags,
-                               NULL, NULL, NULL, NULL, NULL,
-                               NULL, NULL, NULL, NULL, NULL,
-                               error);
+  return g_uri_split_network (uri_string, flags, NULL, NULL, NULL, error);
 }
 
 
diff --git a/glib/guri.h b/glib/guri.h
index a8396f4e6..93d2ec59b 100644
--- a/glib/guri.h
+++ b/glib/guri.h
@@ -110,7 +110,7 @@ gboolean     g_uri_split_network    (const gchar  *uri_string,
                                      GError      **error);
 
 GLIB_AVAILABLE_IN_2_66
-gboolean     g_uri_is_valid         (const gchar  *uri_ref,
+gboolean     g_uri_is_valid         (const gchar  *uri_string,
                                      GUriFlags     flags,
                                      GError      **error);
 
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 70cee76e9..be70b5d6a 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -1267,7 +1267,9 @@ test_uri_is_valid (void)
   g_assert_true (g_uri_is_valid ("http://\xc3\x89XAMPLE.COM/";, G_URI_FLAGS_NONE, NULL));
 
   g_assert_true (g_uri_is_valid ("  \r http\t://f oo  \t\n ", G_URI_FLAGS_NONE, NULL));
-  g_assert_true (g_uri_is_valid ("  \r http\t://f oo  \t\n ", G_URI_FLAGS_PARSE_STRICT, NULL));
+  g_assert_false (g_uri_is_valid ("  \r http\t://f oo  \t\n ", G_URI_FLAGS_PARSE_STRICT, &error));
+  g_assert_error (error, G_URI_ERROR, G_URI_ERROR_BAD_SCHEME);
+  g_clear_error (&error);
 
   g_assert_false (g_uri_is_valid ("http://[::192.9.5.5/ipng";, G_URI_FLAGS_NONE, &error));
   g_assert_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST);


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