* fix list parsing

This commit is contained in:
djcb 2013-05-13 23:01:53 +03:00
parent 4174ac7ed2
commit 50fc992ae2
2 changed files with 12 additions and 16 deletions

View File

@ -263,20 +263,22 @@ mu_str_esc_to_list (const char *strings)
GSList *lst;
GString *part;
unsigned u;
gboolean quoted;
gboolean quoted, escaped;
g_return_val_if_fail (strings, NULL);
part = g_string_new (NULL);
for (u = 0, lst = NULL, quoted = FALSE;
for (u = 0, lst = NULL, quoted = FALSE, escaped = FALSE;
u != strlen (strings); ++u) {
char kar;
kar = strings[u];
if (kar == '\\')
if (kar == '\\') {
escaped = !escaped;
continue;
}
if (quoted && kar != '"') {
g_string_append_c (part, kar);
@ -285,7 +287,10 @@ mu_str_esc_to_list (const char *strings)
switch (kar) {
case '"':
quoted = !quoted;
if (!escaped)
quoted = !quoted;
else
g_string_append_c (part, kar);
continue;
case ' ':
if (part->len > 0) {

View File

@ -35,16 +35,6 @@
#include "mu-msg-prio.h"
#define ASSERT_EQL(S1,S2) \
do { \
const char *s1 = (S1); \
const char *s2 = (S2); \
if (g_strcmp0 (s1,s2) != 0) { \
g_printerr ("error: '%s' != '%s'\n", s1, s2); \
g_assert (0); \
} \
} while (0)
static void
@ -154,7 +144,7 @@ test_mu_str_esc_to_list (void)
{ "maildir:sent items",
{"maildir:sent", "items", NULL}},
{ "\"maildir:sent items\"",
{"\"maildir:sent items\"", NULL, NULL}},
{"maildir:sent items", NULL, NULL}},
};
for (i = 0; i != G_N_ELEMENTS(strings); ++i) {
@ -162,7 +152,8 @@ test_mu_str_esc_to_list (void)
unsigned u;
lst = mu_str_esc_to_list (strings[i].str);
for (cur = lst, u = 0; cur; cur = g_slist_next(cur), ++u)
g_assert_cmpstr ((const char*)cur->data,==,strings[i].strs[u]);
g_assert_cmpstr ((const char*)cur->data,==,
strings[i].strs[u]);
mu_str_free_list (lst);
}
}