diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-05 01:53:56 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-05 01:53:56 (EDT) |
commit | 0493875f09621e3495c95199da54b49910cb87fd (patch) | |
tree | 0f5f8eb249e9f983bd6e4b280afe63c82ba5c4e6 | |
parent | 25bf6ca0f9691471f6714a1dd0c62c22b62641a2 (diff) | |
download | marquee-0493875f09621e3495c95199da54b49910cb87fd.zip marquee-0493875f09621e3495c95199da54b49910cb87fd.tar.gz marquee-0493875f09621e3495c95199da54b49910cb87fd.tar.bz2 |
Revert "src/about.c: Use strtok_r() to parse query strings"
This reverts commit a1fa82f65eceddd76861ce132c8b1b9a458eb0de.
strtok_r() doesn't properly handle empty tokens, e.g.:
tabs.new=&tabs.home=&tabs.background=on&tabs.warn-on-close=on&...
-rw-r--r-- | src/about.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/about.c b/src/about.c index c668b94..47d0c5b 100644 --- a/src/about.c +++ b/src/about.c @@ -19,8 +19,6 @@ * along with Marquee. If not, see <http://www.gnu.org/licenses/>. */ -#define _POSIX_C_SOURCE 200809L - #include <string.h> #include <webkit2/webkit2.h> @@ -33,18 +31,28 @@ static GHashTable * parse_query_string(gchar *str) { GHashTable *hash_table; - gboolean first; - gchar *saveptr; gchar *key; gchar *val; hash_table = g_hash_table_new(g_str_hash, g_str_equal); - first = TRUE; - while ((key = strtok_r(first ? str : NULL, "=", &saveptr))) { - first = FALSE; - val = strtok_r(NULL, "&", &saveptr); + while (*str) { + key = str; + for (; *str && *str != '='; ++str); + if (!*str) { + g_hash_table_insert(hash_table, key, NULL); + break; + } + *str = '\0'; + val = ++str; + for (; *str && *str != '&'; ++str); + if (!*str) { + g_hash_table_insert(hash_table, key, val); + break; + } + *str = '\0'; g_hash_table_insert(hash_table, key, val); + ++str; } return hash_table; |