summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2020-06-30 17:12:10 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2020-07-07 15:16:22 +0400
commit591d8676ee289bd2b69e38e7765493632e9b4c58 (patch)
treecc85f1a4de46cd92858d07fcfd9ee87e909b456d
parentd022b7199b2c9a1d65f4e72b2e531681ceeecd44 (diff)
downloadglib-591d8676ee289bd2b69e38e7765493632e9b4c58.tar.gz
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>
-rw-r--r--docs/reference/glib/glib-sections.txt1
-rw-r--r--fuzzing/fuzz_uri_parse_params.c2
-rw-r--r--glib/guri.c6
-rw-r--r--glib/guri.h23
-rw-r--r--glib/tests/uri.c20
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)
{