[c22e1a4acbd2d996ff19a852585f9434883c30124f6b118eb9152fe4e5ee7994: 3/8] uri: modify g_uri_parse_params() to take flags
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [c22e1a4acbd2d996ff19a852585f9434883c30124f6b118eb9152fe4e5ee7994: 3/8] uri: modify g_uri_parse_params() to take flags
- Date: Wed, 8 Jul 2020 10:53:28 +0000 (UTC)
commit 591d8676ee289bd2b69e38e7765493632e9b4c58
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Tue Jun 30 17:12:10 2020 +0400
uri: modify g_uri_parse_params() to take flags
This will allow to further enhance the parsing, without breaking API,
and also makes argument on call side a bit clearer than just TRUE/FALSE.
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
docs/reference/glib/glib-sections.txt | 1 +
fuzzing/fuzz_uri_parse_params.c | 2 +-
glib/guri.c | 6 +++---
glib/guri.h | 23 +++++++++++++++++++----
glib/tests/uri.c | 20 +++++++++-----------
5 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 6f2722ade..8e3aefd16 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -3371,6 +3371,7 @@ g_uri_get_query
g_uri_get_fragment
g_uri_get_flags
<SUBSECTION>
+GUriParamsFlags
g_uri_parse_params
<SUBSECTION>
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH
diff --git a/fuzzing/fuzz_uri_parse_params.c b/fuzzing/fuzz_uri_parse_params.c
index b5c311352..6783c0000 100644
--- a/fuzzing/fuzz_uri_parse_params.c
+++ b/fuzzing/fuzz_uri_parse_params.c
@@ -10,7 +10,7 @@ LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
if (size > G_MAXSSIZE)
return 0;
- parsed_params = g_uri_parse_params ((const gchar *) data, (gssize) size, "&", FALSE);
+ parsed_params = g_uri_parse_params ((const gchar *) data, (gssize) size, "&", G_URI_PARAMS_NONE);
if (parsed_params == NULL)
return 0;
diff --git a/glib/guri.c b/glib/guri.c
index 882742aec..e5ca12f77 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -1755,7 +1755,7 @@ str_ascii_case_equal (gconstpointer v1,
* bytes not characters, so it can't be used to delimit UTF-8 strings for
* anything but ASCII characters. You may pass an empty set, in which case
* no splitting will occur.
- * @case_insensitive: whether parameter names are case insensitive
+ * @flags: flags to modify the way the parameters are handled.
*
* Many URI schemes include one or more attribute/value pairs as part of the URI
* value. This method can be used to parse them into a hash table.
@@ -1780,7 +1780,7 @@ GHashTable *
g_uri_parse_params (const gchar *params,
gssize length,
const gchar *separators,
- gboolean case_insensitive)
+ GUriParamsFlags flags)
{
GHashTable *hash;
const gchar *end, *attr, *attr_end, *value, *value_end, *s;
@@ -1791,7 +1791,7 @@ g_uri_parse_params (const gchar *params,
g_return_val_if_fail (length >= -1, NULL);
g_return_val_if_fail (separators != NULL, NULL);
- if (case_insensitive)
+ if (flags & G_URI_PARAMS_CASE_INSENSITIVE)
{
hash = g_hash_table_new_full (str_ascii_case_hash,
str_ascii_case_equal,
diff --git a/glib/guri.h b/glib/guri.h
index 8f2b0bea5..344f7f9bd 100644
--- a/glib/guri.h
+++ b/glib/guri.h
@@ -222,11 +222,26 @@ const gchar *g_uri_get_fragment (GUri *uri);
GLIB_AVAILABLE_IN_2_66
GUriFlags g_uri_get_flags (GUri *uri);
+/**
+ * GUriParamsFlags:
+ * @G_URI_PARAMS_NONE: No flags set.
+ * @G_URI_PARAMS_CASE_INSENSITIVE: whether parameter names are case insensitive.
+ *
+ * Flags modifying the way parameters are handled.
+ *
+ * Since: 2.66
+ */
+GLIB_AVAILABLE_TYPE_IN_2_66
+typedef enum {
+ G_URI_PARAMS_NONE = 0,
+ G_URI_PARAMS_CASE_INSENSITIVE = 1 << 0,
+} GUriParamsFlags;
+
GLIB_AVAILABLE_IN_2_66
-GHashTable * g_uri_parse_params (const gchar *params,
- gssize length,
- const gchar *separators,
- gboolean case_insensitive);
+GHashTable *g_uri_parse_params (const gchar *params,
+ gssize length,
+ const gchar *separators,
+ GUriParamsFlags flags);
/**
* G_URI_ERROR:
diff --git a/glib/tests/uri.c b/glib/tests/uri.c
index 0e46d5c00..f429592ac 100644
--- a/glib/tests/uri.c
+++ b/glib/tests/uri.c
@@ -1271,7 +1271,7 @@ test_uri_parse_params (gconstpointer test_data)
/* Inputs */
const gchar *uri;
gchar *separators;
- gboolean case_insensitive;
+ GUriParamsFlags flags;
/* Outputs */
gssize expected_n_params; /* -1 => error expected */
/* key, value, key, value, …, limited to length 2*expected_n_params */
@@ -1279,15 +1279,13 @@ test_uri_parse_params (gconstpointer test_data)
}
tests[] =
{
- { "", "&", FALSE, 0, { NULL, }},
- { "p1=foo&p2=bar", "&", FALSE, 2, { "p1", "foo", "p2", "bar" }},
- { "p1=foo&p2=bar;p3=baz", "&;", FALSE, 3, { "p1", "foo", "p2", "bar", "p3", "baz" }},
- { "p1=foo&p2=bar", "", FALSE, 1, { "p1", "foo&p2=bar" }},
- { "p1=foo&&P1=bar", "&", FALSE, -1, { NULL, }},
- { "%00=foo", "&", FALSE, -1, { NULL, }},
- { "p1=%00", "&", FALSE, -1, { NULL, }},
- { "p1=foo&P1=bar", "&", TRUE, 1, { "p1", "bar", NULL, }},
- { "=%", "&", FALSE, 1, { "", "%", NULL, }},
+ { "p1=foo&p2=bar;p3=baz", "&;", G_URI_PARAMS_NONE, 3, { "p1", "foo", "p2", "bar", "p3", "baz" }},
+ { "p1=foo&p2=bar", "", G_URI_PARAMS_NONE, 1, { "p1", "foo&p2=bar" }},
+ { "p1=foo&&P1=bar", "&", G_URI_PARAMS_NONE, -1, { NULL, }},
+ { "%00=foo", "&", G_URI_PARAMS_NONE, -1, { NULL, }},
+ { "p1=%00", "&", G_URI_PARAMS_NONE, -1, { NULL, }},
+ { "p1=foo&P1=bar", "&", G_URI_PARAMS_CASE_INSENSITIVE, 1, { "p1", "bar", NULL, }},
+ { "=%", "&", G_URI_PARAMS_NONE, 1, { "", "%", NULL, }},
};
gsize i;
@@ -1317,7 +1315,7 @@ test_uri_parse_params (gconstpointer test_data)
uri = g_memdup (tests[i].uri, uri_len);
}
- params = g_uri_parse_params (uri, uri_len, tests[i].separators, tests[i].case_insensitive);
+ params = g_uri_parse_params (uri, uri_len, tests[i].separators, tests[i].flags);
if (tests[i].expected_n_params < 0)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]