GNOME Bugzilla – Bug 620417
g_uri_unescape_string cannot unescape %00
Last modified: 2018-05-24 12:21:02 UTC
Some HTTP services include escaped binary values (such as 20-byte SHA1 hash) which may include a %00. Currently there is no mechanism to support this properly with glib. I propose something along the lines of: gboolean g_uri_unescape_string_length (const char *escaped_string, const char *illegal_characters, char **unescaped_string, gsize *unescaped_string_length)
@alex: As you are the author of the g_uri_* api, what do you think about this addition?
Would we also need the inverse function, something like: char * g_uri_escape_string_length (const char *unescaped, const char *reserved_chars_allowed, gboolean allow_utf8, gsize unescaped_string_length); I assume g_uri_escape_string() treats \0 as termination of the unescaped string.
I don't think g_uri_*_string_length is the right name... the existing API handles strings, it is binary data that it can't handle. I think this would be a good API: char * g_uri_escape (const guchar *unescaped, gssize unescaped_length, const char *reversed_chars_allowed, gboolean allow_utf8); guchar * g_uri_unescape (const char *escaped_string, const char *illegal_characters, gsize *result_length); GString * g_string_append_uri_data_escaped (GString *string, const char *unescaped, gsize unescaped_length, const char *reserved_chars_allowed, gboolean allow_utf8); The g_uri_* functions are similar to what already exists for g_base64_* (uchar* and gsize, no suffix) as well as the existing g_uri_{encode,decode}_string (all the other arguments). Unfortunately, g_string_append_uri_escaped already exists, and its name is a bit inconsistent with the g_uri_* API, so I think the next best thing is g_string_append_uri_data_escaped, or maybe g_string_append_uri_escaped_data?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/307.