json: set state on final bare string

When we run out of chars and are inside a bare string, set our state
so that the next round will continue instead of looping forever.
This commit is contained in:
Wim Taymans 2020-12-31 17:07:03 +01:00
parent 49d11acde0
commit 799bc13c85
2 changed files with 17 additions and 5 deletions

View file

@ -164,11 +164,13 @@ static inline int spa_json_next(struct spa_json * iter, const char **value)
} }
} }
return (iter->depth == 0 ? if (iter->depth != 0)
(iter->state == __BARE && iter->cur < iter->end ? return -1;
iter->cur - *value : if (iter->state == __BARE) {
0) : iter->state = __STRUCT;
-1); return iter->cur - *value;
}
return 0;
} }
static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type) static inline int spa_json_enter_container(struct spa_json *iter, struct spa_json *sub, char type)

View file

@ -222,6 +222,16 @@ static void test_new_string(void)
spa_assert(!strcmp(pw_properties_get(props, "empty"), "")); spa_assert(!strcmp(pw_properties_get(props, "empty"), ""));
pw_properties_free(props); pw_properties_free(props);
props = pw_properties_new_string("foo=bar bar=baz");
spa_assert(props != NULL);
spa_assert(props->flags == 0);
spa_assert(props->dict.n_items == 2);
spa_assert(!strcmp(pw_properties_get(props, "foo"), "bar"));
spa_assert(!strcmp(pw_properties_get(props, "bar"), "baz"));
pw_properties_free(props);
} }
static void test_update(void) static void test_update(void)