json: handle comments when stripping

Or else everything becomes part of the first comment.
This commit is contained in:
Wim Taymans 2021-02-06 20:45:48 +01:00
parent 0be2959f11
commit 78e2e2c27b

View file

@ -287,19 +287,29 @@ static inline int spa_json_parse_string(const char *val, int len, char *result)
{ {
const char *p; const char *p;
if (!spa_json_is_string(val, len)) { if (!spa_json_is_string(val, len)) {
bool skip = false; bool skip = false, comment = false;
for (p = val; p < val + len; p++) { for (p = val; p < val + len; p++) {
switch (*p) { switch (*p) {
case '\n': case '\r': case '\b': case '\t': case '\f': case '#':
comment = true;
break;
case '\n': case '\r':
comment = false;
break;
case '\b': case '\t': case '\f':
break; break;
case ' ': case ' ':
if (!skip) if (!comment) {
*result++ = *p; if (!skip)
skip = true; *result++ = *p;
skip = true;
}
break; break;
default: default:
*result++ = *p; if (!comment) {
skip = false; *result++ = *p;
skip = false;
}
break; break;
} }
} }