* fix list parsing
This commit is contained in:
11
lib/mu-str.c
11
lib/mu-str.c
@ -263,20 +263,22 @@ mu_str_esc_to_list (const char *strings)
|
|||||||
GSList *lst;
|
GSList *lst;
|
||||||
GString *part;
|
GString *part;
|
||||||
unsigned u;
|
unsigned u;
|
||||||
gboolean quoted;
|
gboolean quoted, escaped;
|
||||||
|
|
||||||
g_return_val_if_fail (strings, NULL);
|
g_return_val_if_fail (strings, NULL);
|
||||||
|
|
||||||
part = g_string_new (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) {
|
u != strlen (strings); ++u) {
|
||||||
|
|
||||||
char kar;
|
char kar;
|
||||||
kar = strings[u];
|
kar = strings[u];
|
||||||
|
|
||||||
if (kar == '\\')
|
if (kar == '\\') {
|
||||||
|
escaped = !escaped;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (quoted && kar != '"') {
|
if (quoted && kar != '"') {
|
||||||
g_string_append_c (part, kar);
|
g_string_append_c (part, kar);
|
||||||
@ -285,7 +287,10 @@ mu_str_esc_to_list (const char *strings)
|
|||||||
|
|
||||||
switch (kar) {
|
switch (kar) {
|
||||||
case '"':
|
case '"':
|
||||||
|
if (!escaped)
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
|
else
|
||||||
|
g_string_append_c (part, kar);
|
||||||
continue;
|
continue;
|
||||||
case ' ':
|
case ' ':
|
||||||
if (part->len > 0) {
|
if (part->len > 0) {
|
||||||
|
|||||||
@ -35,16 +35,6 @@
|
|||||||
#include "mu-msg-prio.h"
|
#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
|
static void
|
||||||
@ -154,7 +144,7 @@ test_mu_str_esc_to_list (void)
|
|||||||
{ "maildir:sent items",
|
{ "maildir:sent items",
|
||||||
{"maildir:sent", "items", NULL}},
|
{"maildir:sent", "items", NULL}},
|
||||||
{ "\"maildir:sent items\"",
|
{ "\"maildir:sent items\"",
|
||||||
{"\"maildir:sent items\"", NULL, NULL}},
|
{"maildir:sent items", NULL, NULL}},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(strings); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(strings); ++i) {
|
||||||
@ -162,7 +152,8 @@ test_mu_str_esc_to_list (void)
|
|||||||
unsigned u;
|
unsigned u;
|
||||||
lst = mu_str_esc_to_list (strings[i].str);
|
lst = mu_str_esc_to_list (strings[i].str);
|
||||||
for (cur = lst, u = 0; cur; cur = g_slist_next(cur), ++u)
|
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);
|
mu_str_free_list (lst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user