From 78e2e2c27b1ca9032eeb0bf456314f12eaf50e71 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 6 Feb 2021 20:45:48 +0100 Subject: [PATCH] json: handle comments when stripping Or else everything becomes part of the first comment. --- spa/include/spa/utils/json.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/spa/include/spa/utils/json.h b/spa/include/spa/utils/json.h index 4ddd8074d..d2530ec88 100644 --- a/spa/include/spa/utils/json.h +++ b/spa/include/spa/utils/json.h @@ -287,19 +287,29 @@ static inline int spa_json_parse_string(const char *val, int len, char *result) { const char *p; if (!spa_json_is_string(val, len)) { - bool skip = false; + bool skip = false, comment = false; for (p = val; p < val + len; 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; case ' ': - if (!skip) - *result++ = *p; - skip = true; + if (!comment) { + if (!skip) + *result++ = *p; + skip = true; + } break; default: - *result++ = *p; - skip = false; + if (!comment) { + *result++ = *p; + skip = false; + } break; } }